Skip to content

What about gensym? #28

Description

@ooichu

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions