class34 - PHYS 5900 Class 34 (11/23/2009) Zi-Wei Lin...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PHYS 5900 Class 34 (11/23/2009) Zi-Wei Lin Rule-Based Programming in the form of a collection of user-defined rules (assignments, function definitions); lhs=rhs i.e. Set[lhs,rhs] lhs^=rhs UpSet[lhs,rhs] lhs:=rhs SetDelayed[lhs,rhs] lhs^:=rhs UpSetDelayed[lhs,rhs] lhs is usually in the form of fname[patt1, patt2, ...] In[1]:= ? UpSet lhs ^ = rhs assigns rhs to be the value of lhs , and associates the assignment with symbols that occur at level one in lhs . Immediate assignments/function-definitions: In[2]:= a = Random @ Integer, 10 D Out[2]= 10 In[3]:= ? a Global`a a = 10 In[4]:= 8 a, a < Out[4]= 8 10, 10 < In[5]:= f @ n_ D * g @ m_ D ^ = Random @ Integer, 8 20, 30 <D ^ H n * m L Out[5]= 20 m n In[6]:= ? f Global`f f : f @ n_ D g @ m_ D = 20 m n In[7]:= ? g Global`g g : f @ n_ D g @ m_ D = 20 m n In[8]:= f @ 2 D * g @ 3 D Out[8]= 64 000 000 In[9]:= f @ 2 D * g @ 3 D Out[9]= 64 000 000 The above 2 calls give the same output. Delayed assignments/function-definitions: In[10]:= b : = Random @ Integer, 10 D In[11]:= ? b Global`b b : = Random @ Integer, 10 D In[12]:= 8 b, b < Out[12]= 8 8, 5 < In[13]:= p @ n_ D * q @ m_ D ^: = Random @ Integer, 8 20, 30 <D ^ H n * m L In[14]:= ? p Global`p p : p @ n_ D q @ m_ D : = Random @ Integer, 8 20, 30 <D n m In[15]:= p @ 2 D * q @ 3 D Out[15]= 729 000 000 In[16]:= p @ 2 D * q @ 3 D Out[16]= 191 102 976 The above 2 calls give different outputs....
View Full Document

This note was uploaded on 04/25/2010 for the course PHYS 5900 taught by Professor Lin during the Fall '09 term at East Carolina University .

Page1 / 6

class34 - PHYS 5900 Class 34 (11/23/2009) Zi-Wei Lin...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online