Shen-js. New version.

210 views
Skip to first unread message

Ramil Farkhshatov

unread,
Aug 17, 2012, 4:08:34 PM8/17/12
to qil...@googlegroups.com
Hello.

New version of Shen-js is released. It passes all tests (tested for Shen
5.0) and has exciting (probably) new stuff:

- It employs brand new KLambda translator `reg-kl`. That deals with
`let`, `lambda`, closures and partial application. It can be used in
translators to any non-lispy language. It helps if a target language
does not have aforementioned lambdas, closures, partial application,
if it has dynamic or weird scope.

- Cleaned I/O system that simplifies implementing custom Shen-js REPLs.

- Simple browser based REPL with clumsy files support is included. It
was tested in Firefox and WebKit browsers (Chrome and Surf).

- Builds by `modulesys` module system.
See [http://github.com/vasil-sd/shen-libs] for details.

Shen-js can be obtained from [http://github.com/gravicappa/shen-js].

For using you will need:

- shen.js
Shen-js itself with included cli repl for use with command line
SpiderMonkey(js), V8 (d8) interpreters.

- shen.html, shen-repl-html.js, io-html5,js
Browser-based REPL.

- README
For running instructions.

For developing you need

* http://github.com/vasil-sd/shen-libs
* http://github.com/gravicappa/reg-kl
* http://github.com/gravicappa/js-kl
* http://github.com/gravicappa/shen-js

Bruno Deferrari

unread,
Aug 17, 2012, 7:23:15 PM8/17/12
to qil...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "Qilang" group.
> To post to this group, send email to qil...@googlegroups.com.
> To unsubscribe from this group, send email to qilang+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/qilang?hl=en.
>

This is great. Good job!

--
BD

Mark Tarver

unread,
Aug 18, 2012, 12:32:51 AM8/18/12
to Qilang
Yes; congrats also. I'm up a little early at the moment (5.30) and
will sleep on a little, but well done and I'll certainly look at this
one wrt KL.

Bruno your Scheme port would be great to include if you want to
support it. The right-to-left thing is not an issue any more -
correct? If so I'll place a link from the download page to wherever
you want to place it.

Thanks both.

Mark
> >   *http://github.com/gravicappa/shen-js
>
> > --
> > You received this message because you are subscribed to the Google Groups "Qilang" group.
> > To post to this group, send email to qil...@googlegroups.com.
> > To unsubscribe from this group, send email to qilang+un...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/qilang?hl=en.

Mark Tarver

unread,
Sep 25, 2012, 2:34:05 PM9/25/12
to Qilang
TBoS now out of the way and contract negotiated I can now give this
work the attention it deserves;

"Working with files is a bit clumsy. It requires manual interventions
and has
limited filesize. Shen-js maintains list of files it has access to
directly on
a page. To add local files into it use button under `Filesystem`
title. To
download written file to your local drive press on that file in a
list.
Currently only Chrome supports naming such files. On firefox specify
correct
name manually."

I'm trying to load a file into your system under Chrome. Any hints on
how to do it?

Mark

On Aug 17, 9:08 pm, Ramil Farkhshatov <ra...@gmx.co.uk> wrote:
> Hello.
>
> New version of Shen-jsis released. It passes all tests (tested for Shen
> 5.0) and has exciting (probably) new stuff:
>
>   - It employs brand new KLambda translator `reg-kl`. That deals with
>     `let`, `lambda`, closures and partial application. It can be used in
>     translators to any non-lispy language. It helps if a target language
>     does not have aforementioned lambdas, closures, partial application,
>     if it has dynamic or weird scope.
>
>   - Cleaned I/O system that simplifies implementing custom Shen-jsREPLs.
>
>   - Simple browser based REPL with clumsy files support is included. It
>     was tested in Firefox and WebKit browsers (Chrome and Surf).
>
>   - Builds by `modulesys` module system.
>     See [http://github.com/vasil-sd/shen-libs] for details.
>
> Shen-jscan be obtained from [http://github.com/gravicappa/shen-js].
>
> For using you will need:
>
>   - shen.js
>     Shen-jsitself with included cli repl for use with command line
>     SpiderMonkey(js), V8 (d8) interpreters.
>
>   - shen.html, shen-repl-html.js, io-html5,js
>     Browser-based REPL.
>
>   - README
>     For running instructions.
>
> For developing you need
>

Ramil Farkhshatov

unread,
Sep 25, 2012, 2:55:30 PM9/25/12
to qil...@googlegroups.com
Mark Tarver <dr.mt...@gmail.com> wrote:

> TBoS now out of the way and contract negotiated I can now give this
> work the attention it deserves;
>
> "Working with files is a bit clumsy. It requires manual interventions
> and has
> limited filesize. Shen-js maintains list of files it has access to
> directly on
> a page. To add local files into it use button under `Filesystem`
> title. To
> download written file to your local drive press on that file in a
> list.
> Currently only Chrome supports naming such files. On firefox specify
> correct
> name manually."
>
> I'm trying to load a file into your system under Chrome. Any hints on
> how to do it?
>
> Mark

Press «Choose files» button under «Filesystem». It opens standard open
file dialog where you can choose files to add. Added files will appear
in a list under the button. Now they are accessible to Shen-js by names
they appear in that list.

Files created in Shen session also appear in Filesystem list and can
be saved to disk by pressing on them.

Mark Tarver

unread,
Sep 25, 2012, 3:32:56 PM9/25/12
to Qilang
Got it.

On 25 Sep, 20:25, Ramil Farkhshatov <ra...@gmx.co.uk> wrote:

Mark Tarver

unread,
Sep 25, 2012, 3:36:06 PM9/25/12
to Qilang
Does write-to-file work under this?

Mark

Ramil Farkhshatov

unread,
Sep 25, 2012, 3:46:30 PM9/25/12
to qil...@googlegroups.com
Mark Tarver <dr.mt...@gmail.com> wrote:

> Does write-to-file work under this?
>
> Mark

It is expected to create a file in Filesystem list which can be saved by
clicking on it.

Mark Tarver

unread,
Sep 25, 2012, 5:09:46 PM9/25/12
to Qilang
Got it; very cool and very interesting.

Mark

On 25 Sep, 20:46, Ramil Farkhshatov <ra...@gmx.co.uk> wrote:

Mark Tarver

unread,
Sep 25, 2012, 5:32:40 PM9/25/12
to Qilang
(@v 1 2 3 <>) may need attention.

mark

Mark Tarver

unread,
Sep 25, 2012, 5:52:01 PM9/25/12
to Qilang
Also (+ 7), (* 8) etc.

Mark

Ramil Farkhshatov

unread,
Sep 26, 2012, 5:29:29 AM9/26/12
to qil...@googlegroups.com
Mark Tarver <dr.mt...@gmail.com> wrote:

> (@v 1 2 3 <>) may need attention.

The reason of error on `(@v 1 2 3 <>)` is misbehaving of Shen reader:

(0-) (define filter-func
_ [] -> []
X [[defun X | B] | _] -> [defun X | B]
X [_ | R] -> (filter-func X R))
filter-func

(1-) (let X (read-file "official/Shen 6.1/K Lambda/macros.kl")
(filter-func shen-vector-macro X))
[defun shen-vector-macro [V550]
[cond [[= [vector 0] V550] [cons vector [cons 0 []]]]
[true V550]]]

while first condition of `cond` is actually [= <> V550].

Mark Tarver

unread,
Sep 28, 2012, 5:03:34 AM9/28/12
to Qilang
(input) does not work - I guess JS blocks it?

Mark

Ramil Farkhshatov

unread,
Sep 28, 2012, 6:56:47 AM9/28/12
to qil...@googlegroups.com
Mark Tarver <dr.mt...@gmail.com> wrote:

> (input) does not work - I guess JS blocks it?

It does not. `(input)` works in command line version of Shen-js. The
problem in Shen's REPL organisation: it poll input which is impossible
in html version. At least I couldn't find working solution.

HTML version has two input buffers. First one is is filled from text
form. On each fill action buffer is processed via
`shenjs-repl-split-input` (see shen-js.shen[1]). Valid input is moved
into second input buffer which is used by `read-byte`. Then
`shen-read-evaluate-print` is called. So when `(input)` is called second
input buffer is already empty.

1. https://github.com/gravicappa/shen-js/blob/9e000c4d179d8ab9c31df552698401f66e2bc9a7/shen-js.shen

Is see two solutions.

1. Introduce function like `shen-repl-consume-input` which maintains its
own internal buffer and input:

\* "(in" is stored in a buffer *\
(shen-repl-consume-input "(in")

\* (input) is called *\
(shen-repl-consume-input "put)")

\* "input-value" is stored in a buffer *\
(shen-repl-consume-input "input-value")

\* buffer is read by (input) *\
(shen-repl-consume-input eof)

2. Introduce `shen-read-evaluate-print-expr` which reads and evaluates
single expression.

Mark Tarver

unread,
Oct 4, 2012, 4:08:38 PM10/4/12
to Qilang
this version is now in the download section

Mark

On Sep 28, 12:07 pm, Ramil Farkhshatov <ra...@gmx.co.uk> wrote:
> Mark Tarver <dr.mtar...@gmail.com> wrote:
> > (input) does not work - I guess JS blocks it?
>
>   It does not. `(input)` works in command line version of Shen-js. The
> problem in Shen's REPL organisation: it poll input which is impossible
> in html version. At least I couldn't find working solution.
>
>   HTML version has two input buffers. First one is is filled from text
> form. On each fill action buffer is processed via
> `shenjs-repl-split-input` (see shen-js.shen[1]). Valid input is moved
> into second input buffer which is used by `read-byte`. Then
> `shen-read-evaluate-print` is called. So when `(input)` is called second
> input buffer is already empty.
>
> 1.https://github.com/gravicappa/shen-js/blob/9e000c4d179d8ab9c31df55269...

Ramil Farkhshatov

unread,
Dec 4, 2012, 4:10:42 PM12/4/12
to qil...@googlegroups.com, emeka...@yahoo.com
eigenfunction <emeka...@yahoo.com> wrote:

> how do I use shen.js in a webpage?
> Let's say i want (+ 1 1) to be shown as alert(2) in a webpage, how do I go
> about that?
> thx.

First you need to load `shen.js` but before define a global variable
`shenjs_external_repl` and set it to `true` to prevent shenjs to try to
start a repl.

Then you need a function to evaluate Shen code from a string. The
simpliest way is to define such a function in Shen:

(define shenjs-evalstr-aux
X -> (eval (head (compile (function shen-<st_input>)
(map string->n (explode X))))))

Then translate it to javascript:

(pr (js-from-kl
(js-kl-from-shen
[define shenjs-evalstr-aux
X -> [eval [head [compile [function shen-<st_input>]
[map string->n [explode X]]]]]])))

You will get something like:

shenjs_evalstr_aux = [shen_type_func,
function shen_user_lambda709(Arg708) {
if (Arg708.length < 1) return [shen_type_func, shen_user_lambda709, 1, Arg708];
var Arg708_0 = Arg708[0];
return (function() {
return shenjs_call_tail(shen_eval, [shenjs_call(shen_head, [shenjs_call(shen_compile, [[shen_type_symbol, "shen-<st_input>"], shenjs_call(shen_map, [[shen_type_symbol, "string->n"], shenjs_call(shen_explode, [Arg708_0])]), []])])]);})},
1,
[],
"shenjs-evalstr-aux"];
shenjs_functions["shen_shenjs-evalstr-aux"] = shenjs_evalstr_aux;

And finally add some routine for convenience:

function shenjs_evalstr(str) {
var x = shenjs_call(shenjs_evalstr_aux, [str]);
return shenjs_call(shen_intmake_string, [\"~A\", [shen_tuple, x, []]]);
}

Which then can be used like this:

alert(shenjs_evalstr("(+ 1 1)")

Hope this helps.

Ramil Farkhshatov

unread,
Dec 4, 2012, 11:36:10 PM12/4/12
to qil...@googlegroups.com, artella...@googlemail.com
> Is there anything I can do to get round this error? Thanks

You can try to make `totalPrimes` function tail recursive.

jo...@mentics.com

unread,
Dec 4, 2012, 11:59:46 PM12/4/12
to qil...@googlegroups.com
> (define totalPrimes
> {number --> number}
> 1 -> 0
> I -> (if (= (divisible I) false) (+ 1 (totalPrimes (- I 1))) (+ 0
> (totalPrimes (- I 1)))))

This is not tail recursive. So it's trying to create a call stack
10,000 deep. You'll need to rewrite it so the totalPrimes call is in
tail position.

Or use a fold (where the fold impl uses tail call).
Reply all
Reply to author
Forward
0 new messages