Giter Club home page Giter Club logo

Comments (2)

ooichu avatar ooichu commented on July 16, 2024 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.

tau-dev avatar tau-dev commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.