Comments (2)
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)
))
from fe.
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)
))
from fe.
Related Issues (20)
- how to make an eval function? HOT 4
- Implementing OOP (Structs or objects) for fe HOT 1
- how do you extract values from the code? HOT 3
- Completely black window HOT 1
- Check amount of passed arguments HOT 2
- `fe_write()` crashes on circular lists
- Plans in supporting bytecode compilation? HOT 1
- How do you propose to use `mark` and `gc` of the `fe_Handlers` structure?
- Minor warning HOT 4
- 68k runtime issue HOT 11
- What about `gensym`? HOT 2
- `is` is sometimes incorrect because `==` does not work for floating-point comparison in C HOT 2
- Motivation, minimalism, live AST HOT 4
- Is this a floating point problem? HOT 1
- Strange behavior with macro expanding HOT 1
- Making it a tutorial? HOT 2
- Thanks for publishing aria and fe!
- no-op in eval: P_FN/P_MAC HOT 2
- Handling user input? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe.