On 22/08/2014, at 11:35 PM, srean wrote:
> Looks good, all of it. What is this BTW
>
> let ?v = x in 0 <= v and v < 10
>
> could you break that up into its parts.
Sure: its a let expression:
let pattern = value in expression
For example:
let ?x = 1 in x + x
has the value 2.
Let expression has a very low precedence, the lowest in fact.
Which means the RHS expression "goes on forever" :)
Until ended by end of statement or whatever.
It is syntactic sugar for:
match value with
| pattern => expression
endmatch
which is why you need to write let ?x with a question mark,
to denote a pattern variable.
Hence you can also write:
let ?x, _ = 1,2 in x + x
since it just means
match 1,2 with
| ?x, _ => x + x
endmatch
And of course
cond1 and cond2
means what it says: the logical conjunction of two predicates,
i.e. bool expressions.
you can also do this:
let Some ?x = optional in x
which will throw an exception if the optional bit happens
to be None, just as a failed match throws an exception.
let .. in .. is the standard binder used in ML like functional
languages. Ocaml and Scheme and Felix all have it.
Haskell uses a backwards let, Haskell being backwards ...
x + x where x = 1
which is the same meaning as
let ?x = 1 in x + x
let bindings crap all over block structure, because the temporary
variable goes out of scope after the expression. So you can write
nice stuff like
let ?x =
let ?y = 3 in y + y
in
x + x
which of course has value 12 since y is 3, x is 6 and the whole
thing is worth 12. With block structure:
var y = 3;
var x = y + y;
var result = x + x;
but the problem is y and x remain in scope. In Felix you can hide them:
var result =
#{ var x = #{var y = 1; y + y }; x + x }
;
but the let form is easier :)
[Note that #f means the same as f(), saves many hassles as above.
A { ... } form ending in an expression is a function which returns the
final expression. If it ends in a statement its a procedure, unless
it ends in a return statement returning a value in which case its
a function .. :]
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language