How to implement REPL with eval-top-level

Asked by higepon(Taro Minowa) on 2008-08-25

Hi.

I'm using psyntax-r6rs-rev4 for Mosh Scheme.
psyntax is great library, it works well for Mosh.

I want to implment a REPL for Mosh using psyntax.

I read your ikarus.cafe.ss and leppie's IronScheme.

(1) ikarus's REPL
ikarus's REPL uses eval-top-level.

(2) IronScheme's REPL
At main.ss of psyntax, bind eval-top-level to eval-r6rs.
  (set-symbol-value! 'eval-r6rs eval-top-level)

And invoke from C# using the name 'eval-r6rs.

(3) Mosh's REPL
I have tried two ways (a) and (b), it causes same error.

(a) I wrote REPL at main.ss of psyntax.

(define (repl)
  (define (rec)
    (display "mosh>")
    (guard (e
            (for-each-with-index
             (lambda (i x)
               (cond
                [(who-condition? x)
                 (format #t " ~d. &who: ~a\n" i (condition-who x))]
                [(message-condition? x)
                 (format #t " ~d. &message: ~s\n" i (condition-message x))]
                [(violation? x)
                 (format #t " ~d. ~a\n" i (record-type-name (record-rtd x)))]
                [(irritants-condition? x)
                 (format #t " ~d. &irritants: ~s\n" i (condition-irritants x))]
                [else
                 (format #t " ~d. ~a\n" i (record-type-name (record-rtd x)))]))
             (simple-conditions e))))
    (let ([obj (read (current-input-port))])
      (if (eof-object? obj)
          (exit)
        (display (eval-top-level obj)))))
  (rec))

(b) (set-symbol-value! 'eval-r6rs eval-top-level) at main.ss of psyntax.
And invoke it from repl.scm after loaded psyntax.pp.

The Error is like following.
mosh>(display 'hige)
   1. &assertion
   2. &who: eval
   3. &message: "unbound variable"
   4. &irritants: ("G39")

Is this a kind of mangling problem?

Thank you for your great library.

---
Taro Minowa(Higepon)

http://www.monaos.org/
http://code.google.com/p/mosh-scheme/

Question information

Language:
English Edit question
Status:
Expired
For:
r6rs-libraries Edit question
Assignee:
No assignee Edit question
Last query:
2008-10-21
Last reply:
2008-11-05
leppie (leppie) said : #1

Here are some ideas/suggestions:

> Is this a kind of mangling problem?

This could be.

> (set-symbol-value! 'eval-r6rs eval-top-level)

I only need it to call that proc from C#. I do not think you can ever refer to that symbol.

> (eval-top-level obj)

This is the same as (eval obj (interaction-environment)).

Here is a repl.ss, that I can run from the command line:
(import
  (ironscheme) ; for interaction-environment
  (rnrs eval))

; my read does not behave on current-input when blocking
; entering an empty string will exit
(define (parse-string s)
  (call-with-port (open-string-input-port s) read))

(define (repl)
  (define (rec)
    (display "> ")
    (guard (e (#t (display e) (newline)))
      (let ([obj (parse-string (get-line (current-input-port)))])
        (if (eof-object? obj)
            (exit)
          (begin
            (write (eval obj (interaction-environment)))
            (newline))))))
  (rec))

(let f ()
  (repl)
  (f))

Hope this helps :)

higepon(Taro Minowa) (higepon) said : #2

Hi.

Thank you for your help and advise.

> This is the same as (eval obj (interaction-environment)).

I can't find (interaction-environment) in my psyntax.
But found it in your IronScheme's psyntax and rev9 of ~leppie/r6rs-libraries/ironscheme.dev.

So all I have to do may be upgrade psyntax to newer one.
It will be hard to upgrade, but I try.

Thanks.

higepon(Taro Minowa) (higepon) said : #3

Please keep this still be open.
I will write some result for my trial.

leppie (leppie) said : #4

> Please keep this still be open.

Oops, I only have 2 options :)

> So all I have to do may be upgrade psyntax to newer one.
> It will be hard to upgrade, but I try.

Once you upgraded, it will be much easier to keep insync.

I can try help, but last time I checked mosh didnt run under windows. Is that still the case? I do not have a Linux set up currently, but will try add it as a VM to my 'media center' box I will be building.

leppie (leppie) said : #5

I was thinking about your previous request for help, and maybe I can generate a 'bootfile' for you.

I need to know a few things:
- do you have case-lambda?
- do you have library-letrec*?
- do you have limitations on the naming of gensyms?
- do you have hashtables implemented?
- do you have records implemented?

Not sure what else I would need, but that should be most of the 'dependencies'.

Cheers

leppie

higepon(Taro Minowa) (higepon) said : #6

>I can try help, but last time I checked mosh didnt run under windows.

Thank you for your kindness.
Sorry, Mosh supports Linux, OSX and FreeBSD.

I use Ubuntu Linux and OSX for developing
so with each of them, you can build Mosh easily.

I have succeeded in expanding rev1 of ~leppie/r6rs-libraries/ironscheme.dev.
I try rev2 next.

higepon(Taro Minowa) (higepon) said : #7

My answers are
- do you have case-lambda? => No.
- do you have library-letrec*? => No.
- do you have limitations on the naming of gensyms?
  => What are the expected limitations?
     gensyms is implemented as " sprintf(ubuf, "G%d", next++);" internally.
     But we can override it or make new one.
- do you have hashtables implemented? => Yes (svn trunk).
- do you have records implemented? => Yes (svn trunk).

Launchpad Janitor (janitor) said : #8

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

higepon(Taro Minowa) (higepon) said : #9

Finally I succeeded in REPL with psyntax.

There are two required for REPL.

(1) (define-option if-wants-global-defines #f) required.
    For REPL, psyntax genarated direct set! code without define.

(2) gensym & ungensym
    ungensym helps demangling identifier's name.

Thanks to leppie for helping me.

You can use "import " on REPL.

You only need to add "import" to identifier->library-map.

(define identifier->library-map
  '(
    ;;;
    (import i)

Launchpad Janitor (janitor) said : #11

This question was expired because it remained in the 'Open' state without activity for the last 15 days.