Arc Forumnew | comments | leaders | submitlogin
Eval Inquirry
4 points by eds 5903 days ago | 7 comments
So I was messing around with eval and I found something that confused me:

  arc> (eval '(- 3 4))
  -1
  arc> (eval `(,- 3 4))
  Error: "Bad object in expression #<primitive:->"
I thought that Arc evaluated the first position and performed a function call if it was a function object. I don't see why it should matter if the function is passed in directly, or through a symbol. But apparently the former doesn't work.

If anyone could help explain this I would appreciate it.



4 points by nlavine 5903 days ago | link

The easiest fix is just to add a line to the literal? function in ac.scm so that it accepts procedures:

  (define (literal? x)
    (or (boolean? x)
        (char? x)
        (string? x)
        (number? x)
        (procedure? x) ; New line!
        (eq? x '())))
However, pg didn't accept it into arc1, so there may be some problem with it that I haven't figured out (or, he might just have ignored it).

-----

1 point by elibarzilay 5902 days ago | link

He also wanted to be able to have hash tables in eval, which is easy to get by adding another line to the above, allowing `hash-table?' as literals.

-----

4 points by cadaver 5903 days ago | link

This may shed some light on the matter: http://arclanguage.com/item?id=899

-----

1 point by eds 5903 days ago | link

Thanks, although it seems to regard mostly macros.

PG commented "The single biggest compromise I had to make because of MzScheme was not being able to put objects like functions and hashtables into macroexpansions." Not exactly sure what he meant by that, or if it had anything to do with the evaling functions directly.

I guess what I am really wondering is if there is an intrinsic reason why evaling a function directly can't work, or if support for it just doesn't happen to be in Arc currently because PG never needed it.

-----

3 points by cadaver 5902 days ago | link

From the tutorial:

  [Note: Like functions, hash tables can't be printed out in a way
  that can be read back in.  We hope to fix that though.]
The problem that I see with macros+hashtables in macroexpansion, as well as with printing/reading-back-in functions+macros+hashtables, is that currently an expression is compiled, before it is evaled, and loses its original uncompiled form. That's why macros are currently not truly first-class.

If used with eval or in macroexpansions this only causes a problem with macros and hashtables, not with functions or hashtables used as functions. Like nlavine pointed out, it only takes an additional line of code in "ac" to make your example work.

-----

2 points by soegaard 5901 days ago | link

Hash tabels ought to be easy to fix by setting the MzScheme parameter print-hash-table to #t. See

http://download.plt-scheme.org/doc/352/html/mzscheme/mzschem...

-----

3 points by bramsundar 5903 days ago | link

The way I understand it, when you type in (eval '(- 3 4)) at the shell, eval passes its argument to ac. Ac in turn calls ac-call for things that are function calls. Ac-call converts an arc function call into an equivalent scheme form. During this process, it finds the underlying scheme name of an arc function by calling ac-var-ref. If you just pass in the actual function, it can't find the scheme name of the function and so can't evaluate it.

-----