[racket] Use of map and eval to evaluate symbol in namespace

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Aug 10 05:14:21 EDT 2014

On Sat, Aug 9, 2014 at 8:27 AM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> Sounds like a good rule of thumb.  Two suggestions to add:
> * Maybe there could also be a second rule of thumb, like, "If you need
>   arbitrary Racket expressions, then consider whether you can do it
>   with one of the following patterns: [list some patterns involving
>   combinations of syntax extension, custom #lang, dynamic requires,
>   considering whether config files can actually be compile-time #lang,
>   etc.]"  This is less important than the first rule of thumb.

That would be a good bottom addition -- after all the discouraging is
done since (IIUC) your targeting valid eval cases in ways that are
similar to it.

> * When we list typical newbie cases that don't actually require
>   "eval", we can expect that newbie will immediately want an example
>   of the non-"eval" way to do that typical thing.  At the very least,
>   an example showing, say, good use of hashes in parameters, with a
>   sensible thin abstraction layer over it, for that case.  These
>   examples would be tedious to work through and write up well, but
>   someday some knowledgeable and benevolent person will do it.  (I am
>   not this person.  [...]

+1, in general, but it sounds like a hard thing to do.  IME, the big
problem is that usually when people get to ask about how to do something
with eval, that something is already an abstraction of their real
motivation.  The best example of that is the common case of trying to
get from a symbol/string that names a binding to its value -- it could
be that they need to use a hash table, or maybe they don't know that
they can use functions (as in +) directly instead of names ('+), or they
don't know how to use symbols and try to map them to integers in an
attempt to implement some enum-like thing, etc.  I've done a quick scan
of eval-tagged questions on SO (crossed with `python', `javascript', and
`lisp'), and I couldn't find questions that could be grouped.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.