guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multi-language scripts


From: Matt Wette
Subject: Re: Multi-language scripts
Date: Sat, 22 Aug 2020 08:22:12 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0



On 8/22/20 7:53 AM, Stephen Scheck wrote:
Matt Wette wrote:

maybe this?

(use-modules (system base language))
(current-language (lookup-language 'ecmascript))
It doesn’t work:

     scheme@(guile-user)> (use-modules (system base language))
     scheme@(guile-user)> (lookup-language ‘ecmascript)
     $1 = #<<language> name: ecmascript title: ECMAScript reader: #<procedure 7f939b1bb558 at 
language/ecmascript/spec.scm:33:16 (port env)> printer: #<procedure write (_ #:optional _)> parser: #f 
compilers: ((tree-il . #<procedure compile-tree-il (exp env opts)>)) decompilers: () evaluator: #f joiner: #f 
for-humans?: #t make-default-environment: #<procedure make-fresh-user-module ()>>
     scheme@(guile-user)> (current-language $1)
     $2 = scheme
     scheme@(guile-user)> display("We should be in JavaScript now, but we 
aren’t!\n”);
     $3 = #<procedure display (_ #:optional _)>
     ERROR: Wrong type to apply: "We should be in JavaScript now, but we 
aren’t!\n”
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.


Also, even if it did, it would be problematic switching back - you’d need to do 
something along these lines in Scheme first:

(define (string_to_symbol sym) (string->symbol sym))
(define (lookup_language lang) (lookup-language lang))
(define (set_current_language lang) (set-current-language! lang)) ;; assuming 
set-current-language! actually existed…

This wouldn’t work, obviously, in the general case for other languages. I don’t 
really want to use JavaScript, I was just using it as an example.

I really just want some way to enable the REPL reader when you pass a script to 
Guile with the -s switch from the command line so you can embed `,language` 
meta-commands in the script file.


I think the issue is that while the repl processes one input (line) at a time guile handles files by compiling a file at a time.  I think you'd have to write code to process files an input (line) at a time.  Maybe this could be a procedure that takes the name of the file, generates a repl and feeds the repl from the file
one line at a time.

(I have played with the compiler code a bit in writing guile-hosted parser/interpreters
for javascript, matlab, tcl and others.   Try web search for guile nyacc.)

Matt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]