rxi / fe

A tiny, embeddable language implemented in ANSI C
MIT License
1.3k stars 81 forks source link

What about `gensym`? #28

Open ooichu opened 1 year ago

ooichu commented 1 year ago

The gensym function can be very useful in macros. It can be effectively implemented by creating symbols that are not added to symlist, so such symbols can be removed by the garbage collector and may not have a string representation. This is how you can change the implementation of the for macro from 'scripts/macros.fe' using gensym:

(= for (mac (item lst . body)
  (let for-iter (gensym))
  (list 'do
    (list 'let for-iter lst)
    (list 'while for-iter
      (list 'let item (list 'car for-iter))
      (list '= for-iter (list 'cdr for-iter))
      (cons 'do body)
    )
  )
))

It is assumed that for-iter should not be visible when body is called. I'm implemented it in my fork.

ghost commented 1 year ago

@ooichu It seems this project is dead.

ooichu commented 1 year ago

Maybe. But I hope @rxi just doesn't have time for his projects right now. Most of his projects are not dead, but completed. This project is more complete than dead. I'm very fascinated by the minimalism, simplicity, and practicality of this language and sometimes find (I think) possible improvements.