fe
fe copied to clipboard
'let': no recursive functions
What is a lisp without recursion? Not very useful. Therefore it is a pity that with fe you cannot specify a recursive function, using 'let'. You are forced to use '=', but then the function gets global scope which is not always wanted. Maybe there is a small modification possible to solve this problem?
You can have a recursive local function by first declaring the variable with let and then setting it, e.g. with such a macro:
(= reclet (mac (name def)
(list 'let name)
(list '= name def)
))
You can have a recursive local function by first declaring the variable with let and then setting it, e.g. with such a macro:
(= reclet (mac (name def) (list 'let name) (list '= name def) ))
This is wrong! This macro does not actually create a local variable, it works literally as (= name def)
because (list 'let name)
(by the way, (let name)
raises 'too few arguments' error) form is omitted. If you want to make a macro that evaluates multiple forms, you have to use do
. Then, we get the following:
(= reclet (mac (name def)
(list 'do
(list 'let name)
(list '= name def)
)
))
But that macro is useless. So, it looks like in fe you can't create a macro that creates a local variable and does something else in the calling environment.
What is a lisp without recursion? Not very useful. Therefore it is a pity that with fe you cannot specify a recursive function, using 'let'. You are forced to use '=', but then the function gets global scope which is not always wanted. Maybe there is a small modification possible to solve this problem?
You can do this following way (just a spontaneous example):
(= fib-sqr (fn (x)
; create local recursive function
(let fib nil)
(= fib (fn (x)
(if (<= 2 x) (+ (fib (- x 2)) (fib (- x 1))) x)
))
; call it
(let n (fib x))
(* n n)
))