unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Multi-language scripts
@ 2020-08-21 18:22 Stephen Scheck
  2020-08-21 18:36 ` Matt Wette
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Scheck @ 2020-08-21 18:22 UTC (permalink / raw)
  To: guile-user

I'm trying to invoke `guile -s script` where script contains something like
this:

    ,language ecmascript
    display("Hello JavaScript!\n");
    ,language scheme
    (display "Hello Guile!\n")

However, REPL meta-commands do not seem to be available when passing a
script file to Guile with the -s switch.

Does anybody know if there's any way to make it work?


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Multi-language scripts
@ 2020-08-21 19:17 Stephen Scheck
  2020-08-22  2:47 ` Matt Wette
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Scheck @ 2020-08-21 19:17 UTC (permalink / raw)
  To: matt.wette; +Cc: guile-user

Matt Wette wrote:

> Did you try `guile --language=emacscript’?
>
> mwette$ cat zz.js
> display("hello\n”);
>
> mwette$ guile --language=ecmascript zz.js
> hello

The intent is that I want it to change language in the middle of the script.




^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Multi-language scripts
@ 2020-08-22 14:53 Stephen Scheck
  2020-08-22 15:22 ` Matt Wette
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Scheck @ 2020-08-22 14:53 UTC (permalink / raw)
  To: matt.wette; +Cc: guile-user

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.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-22 15:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 18:22 Multi-language scripts Stephen Scheck
2020-08-21 18:36 ` Matt Wette
  -- strict thread matches above, loose matches on Subject: below --
2020-08-21 19:17 Stephen Scheck
2020-08-22  2:47 ` Matt Wette
2020-08-22 14:53 Stephen Scheck
2020-08-22 15:22 ` Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).