Call a function: Difference between revisions

Latitude language added
(Latitude language added)
Line 2,811:
}
# unbounded list on keys bounded by closing parenthesis of sort</lang>
 
=={{header|Latitude}}==
 
Like Ruby, Latitude doesn't have functions in the traditional sense, only methods. Methods can be called with parentheses, as in many languages. If a method takes no arguments, the parentheses may be omitted. If a method takes a single argument and that argument is a literal (such as a literal number or string), then the parentheses may also be omitted. Additionally, Latitude provides an alternative syntax for method calls which replaces the parentheses with a colon.
 
<lang>foo (1, 2, 3). ; (1) Ordinary call
foo (). ; (2) No arguments
foo. ; (3) Equivalent to (2)
foo (1). ; (4) Single-argument function
foo 1. ; (5) Equivalent to (4)
foo (bar). ; (6) Parentheses necessary here since bar is not a literal
foo: 1, 2, 3. ; (7) Alternative syntax, equivalent to (1)</lang>
 
Although methods themselves can be passed around as first-class values, the method evaluation semantics often make such an approach suboptimal. If one needs a first-class function in the traditional sense, the usual approach is to wrap it in a <code>Proc</code> object and then call it explicitly as needed.
 
<lang>myProc := proc { foo. }.
myProc call (1, 2, 3).</lang>
 
If you want to write a function which can accept either a <code>Proc</code> or a method object (as many standard library functions do, for convenience), you may use the <code>shield</code> method to ensure that the object is a <code>Proc</code>. <code>shield</code> wraps methods in a <code>Proc</code> while leaving objects which are already procedures alone.
 
<lang>myProc1 := #'foo shield.
myProc2 := proc { foo. }.
myProc3 := proc { foo. } shield.</lang>
 
All three of the above procedures will act the same.
 
=={{header|LFE}}==
37

edits