Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SICP metacircular interpreter question

Name: Anonymous 2011-09-27 7:59

How does it handle sequences in input? If it's in a define or lambda or begin or whatever then it follows those respective paths in the eval branch, all of which lead to eval-sequence. But if it's just
(define a 1) (define b 2)
how's it interpret that?

Name: Anonymous 2011-09-27 8:00

Goddamn parser.
read: > (define a 1) (define b 2)
as in at the input prompt.

Name: Anonymous 2011-09-27 8:31

1. It reads (define a 1) (define b 2) left-to-right
2. Stops at ')' of (define a 1)
3. Pushes 2 onto the register
4. pushes a onto the register
5. looks up define, since it's next to the (.
6. Executes define given a and 1 as the inputs.
Then goes on to (define b 2) if (define a 1) completed successfully.

I described certain like the register, but the key to understanding Lisp as a philosophy is you need to know how define or even the meta-evaluator responds, you don't need to know how it works.

Hope that helps brah

Name: Anonymous 2011-09-27 8:32

>>3
don't need to know how*

Name: Anonymous 2011-09-27 8:35

Then goes on to (define b 2) if (define a 1) completed successfully
That's what I'm wondering about. For reference, here's the relevant code.

(define (eval exp env)
  ((analyze exp) env))

(define (analyze exp)
  (cond ((self-evaluating? exp)
         (analyze-self-evaluating exp))
        ((quoted? exp) (analyze-quoted exp))
        ((variable? exp) (analyze-variable exp))
        ((assignment? exp) (analyze-assignment exp))
        ((definition? exp) (analyze-definition exp))
        ((if? exp) (analyze-if exp))
        ((lambda? exp) (analyze-lambda exp))
        ((begin? exp) (analyze-sequence (begin-actions exp)))
        ((cond? exp) (analyze (cond->if exp)))
        ((application? exp) (analyze-application exp))
        (else
         (error "Unknown expression type -- ANALYZE" exp))))

Name: Anonymous 2011-09-27 8:43

>>5
I'd say you probably have define return a successful complete status, it heads on to the next one.

A better description might include TWO eval entities, one which handles the whole line, and the other which is only given the first complete operation, which is what heads off to the evaluator. Upon complete, it then returns "complete" to the primary evaluator, which is a special construction so that it sets the return value to null/not-complete, then reads the next operation.

Name: Anonymous 2011-09-27 8:47

I'm asking specifically about the metacircular interpreter implemented in SICP 4.1. I can't find anywhere in the code which handles this, yet it works.

Name: Anonymous 2011-09-27 8:48

>>7
I think all you should be able to find is the implementation specifications. The creation of an actual interpreter is left as an exercise to the reader.

Name: Anonymous 2011-09-27 8:58

>>8
What the christ are you talking about, the implementation is literally in the goddamned book. When you find that you don't know what's being discussed, stop posting, don't come up with some nonsensical parting shot.

I'm now guessing that read is supposed to slurp one sexp at a time. This would explain the following occurs as soon as you hit return:
;;; M-Eval input:
(define b 2) (define c 3)

;;; M-Eval value:
ok

;;; M-Eval input:

;;; M-Eval value:
ok

Name: Anonymous 2011-09-27 9:01

might i ask what these (metacircular interpreters) are used/useful for in practice? I get the impression nobody has figured out how to properly use them...

..an Ai code generator someday? ...just a code generator would be nice enough, but it has to generate 'New'-ish? code, of course..
and if it solves a problem, even better, but still only par for the course...
Internet explorer 3 can interpret stuff....

Name: Anonymous 2011-09-27 9:02

>>9
Ok, what's the ASM of the implementation for an x86 processor?

And yeah, it should only be handling on sexp at a time.

Name: Anonymous 2011-09-27 14:39

GC is shit.

Name: Anonymous 2011-09-27 21:07

<<10 just thinking, You'd need both a plain old compiler & a metacircular interpreter for 'Good' code generators...

The interpreter is good for checking code line by line, but if you're going to drop a chunk of code into a working program, you'd probably want to compile and make sure the whole block is error free, and won't break down at an arbitrary point a bit further into the execution...

And there's still the problem of generating code....

Name: Anonymous 2011-09-27 21:31

Does intelligence require conciousness?

Perhaps just an 'awake' program would be a better target than an 'intelligent' one..?

Does even generating code require some intelligence / awareness of what needs to be built? It should perhaps also know why it is building a piece code, and most probably at least how it is to build it?

Not knowing what to build -> not building the right stuff
Not knowing how to build..-> trial and error(/) brute
Not knowing why to build..-> building the right stuff for the wrong, or even no reason at all..?

Don't change these.
Name: Email:
Entire Thread Thread List