Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 07 21:16
    CI run 4117496244 passed
  • Feb 07 19:26

    gambiteer on master

    Add support for IBM System/390 … Merge pull request #809 from zv… (compare)

  • Feb 07 19:26
    gambiteer closed #809
  • Feb 05 06:34
    bheesham commented #765
  • Jan 22 06:23
    gambiteer commented #811
  • Jan 22 05:58
    falsifian commented #811
  • Jan 19 14:35
    lassik commented #753
  • Jan 19 14:35
    lassik closed #753
  • Jan 19 14:35
    lassik commented #731
  • Jan 14 14:51
    feeley commented #812
  • Jan 14 13:55
    lassik opened #812
  • Jan 14 10:36
    amirouche closed #808
  • Jan 14 10:36
    amirouche commented #808
  • Jan 12 14:13
    CI run 3902417922 passed
  • Jan 12 12:52

    feeley on master

    CI: use gcc-11 on macOS (gcc-9 … (compare)

  • Jan 12 00:31
    feeley commented #810
  • Jan 11 23:55
    nickmain closed #810
  • Jan 11 23:55
    nickmain commented #810
  • Jan 11 20:51
    MacOS build of CI run 3896600203 failed
  • Jan 11 20:51

    feeley on master

    Create temp dir in /tmp when no… (compare)

Marc Feeley
@feeley
@bentxt Replace Gambit_scm2js(…) by @scm2host@(…) and Gambit_js2scm(…) by @host2scm@(…)
The @foo@ syntax allows the gsc compiler to generate the appropriate low-level identifier for foo (which depends on various compilation options)
moreover, the error ReferenceError: _ScmString is not defined suggests to me that you are linking with an outdated runtime library… make sure you have done make install
François-René Rideau
@fare
Yeah, I suppose using the C backend to compile to WASM would be the natural way to do it. Thanks a lot, Marc! (And congratulations again for such a portable implementation.)
Marc Feeley
@feeley
Some time ago I was interested in a “native” WASM backend, but the fact that WASM did not have a “jump” instruction (for tail calls) and still doesn’t have it make that endeavor rather pointless as there will be no gain in performance over Scheme -> C -> WASM (using emscripten)
François-René Rideau
@fare
Oh, WASM had it, until Microsoft (and Google?) insisted to have it removed.
1 reply
ben.txt
@bentxt

@feeley, thanks a lot for your help. The reason I was working with this example, was because I thought I could avoid the large _gambit.js library. But it is still needed.

I search this forum for hours for a working solution with a custom, minimal js runtime library, because I'm sure there was once a solution posted. I don't need all of Gambit, I think I could even sacrifice macros in order to get a smaller library. Would you mind help me with this quest for a small.js library?

ben.txt
@bentxt
I think I found the example with the custom runtime rts.js: https://gitter.im/gambit/gambit?at=5bc7fb95435c2a518ec448d1

unfortunately I get the following error:
node app.js
/gambit/app.js:503
pc = pc();
^

TypeError: pc is not a function

ben.txt
@bentxt
thank fully I found a more recent solution from @feeley that works: https://mailman.iro.umontreal.ca/pipermail/gambit-list/2020-March/009363.html
Marc Feeley
@feeley
Here’s another one that I have just tested:
$ cat minimal-lib.scm
(declare (extended-bindings) (not safe))

(define (show str)
  (##inline-host-statement "console.log(@scm2host@(@1@));" str))

(define (date)
  (##inline-host-expression "@host2scm@(new Date())"))

(define (##run-each-module)
  (let ((mods (##vector-ref ##program-descr 0)))
    (let loop ((i 1)) ;; start at module after the current one
      (if (##fx< i (##vector-length mods))
          (let ((mod (##vector-ref mods i)))
            ((##vector-ref mod 4)) ;; call module's init procedure
            (loop (##fx+ i 1)))))))

(##run-each-module) ;; run each module (after the current one)
$ cat minimal-app.scm
(show (date))
$ gsc -target js -c minimal-lib.scm
$ gsc -target js -l minimal-lib -exe minimal-app.scm
$ ./minimal-app
2022-06-17T13:59:21.496Z
ben.txt
@bentxt
Thanks a lot! This is very handy. I made a Gist out of it: https://gist.github.com/bentxt/ff4a4ef8e3ee13223613091a052aa641
Btw. how serious is the bitrot (which I read somewhere) of the php backend? It would be very cool to a have a nice frontend for php ...
cs7
@cs7:matrix.org
[m]
PHP is such a broken language (at least years ago when I had to do with it)
broken in a limited sense - primitive, not so useful syntax, types and so on, what form of memory management does it have even and so on
Marc Feeley
@feeley
@bentxt Depends on who is tasked to fix the bitrot! :-) I’m not sure PHP is on a trajectory that makes it an interesting target to put much effort into. I just tried the above minimal-lib example with PHP (suitably modified for PHP) and the generated PHP code needed a few tweaks to get it to work (apparently nested functions are no longer supported except for anonymous functions).
ben.txt
@bentxt
The 3 reasons I find PHP interesting: #1: lots of providers, offering similar shared hosting environments, #2: very simple to setup, #3 relatively fast
cs7
@cs7:matrix.org
[m]
to help debugging what about you figure which column exactly
@bentxt: You mean PHP is ubiquitous? Yea well ok. Node.JS is ubiquitous too?
felix-lipski
@felix-lipski
$ gsc -v
v4.9.3 20180930122740 x86_64-unknown-linux-gnu "./configure '--prefix=/nix/store/w3pg7qf91b63yp5qr1pp3cxyfrww0hvw-gambit-4.9.3/gambit' ..."
$ gsc -h
*** WARNING -- Unknown or improperly placed -h option
this happens for many other flags, it's a clean install on nixos btw
same error
Marc Feeley
@feeley
--help
Marc-André Bélanger
@belmarca
it's a very old version of gambit
I believe the -h flag was added in 2019
Marc Feeley
@feeley
Ah yes, that’s an old Gambit… -h and --help were added a few years ago...
felix-lipski
@felix-lipski
okay, works with a newer version, thanks!
KM
@twoplustwo:matrix.org
[m]
Hello :) I am trying to understand what the 'rest' arguments are in 6.2 "6.2 Extensions to standard special forms" iro.umontreal.ca/~gambit/doc/gambit.html#Extensions-to-standard-special-forms - how are they different from optionals and what are they used for?
Marc Feeley
@feeley

@twoplustwo:matrix.org Take number->string… the first parameter (a number) is required, and the second parameter is optional (a number that is the base) and you cannot pass more than 2 parameters:

> (number->string 42)
"42"
> (number->string 42 2)
"101010"
> (number->string 42 2 111 222 333)
*** ERROR IN (stdin)@3.1 -- Wrong number of arguments passed to procedure
(number->string 42 2 111 222 333)

But sometimes you want to accept any number of parameters, for example the - procedures requires one parameter, but can have any number of additional parameters:

> (- 5)
-5
> (- 5 2)
3
> (- 5 2 1)
2
> (- 5 2 1 111 222 333)
-664

For this situation you need to define the procedure using a rest parameter which will be a list of all the remaining parameters:

> (define (- first . rest) (list 'first= first 'rest= rest))               
> (- 5)
(first= 5 rest= ())
> (- 5 2 1 111 222 333)                                     
(first= 5 rest= (2 1 111 222 333))
KM
@twoplustwo:matrix.org
[m]
Oh and I can just use a dot instead of #!optional. thanks a lot!
This makes perfect sense to me now
Marc Feeley
@feeley
no… the . is the same as #!rest#!optional marks the beginning of optional parameters
> (define (a x y #!optional z) (list 'x= x 'y= y 'z= z))
> (define (b x y #!optional z #!rest rest) (list 'x= x 'y= y 'z= z 'rest= rest))
> (a 1 2)
(x= 1 y= 2 z= #f)
> (a 1 2 3)
(x= 1 y= 2 z= 3)
> (a 1 2 3 4)
*** ERROR IN (stdin)@5.1 -- Wrong number of arguments passed to procedure
(a 1 2 3 4)
1> ,t
> (b 1 2)
(x= 1 y= 2 z= #f rest= ())
> (b 1 2 3)
(x= 1 y= 2 z= 3 rest= ())
> (b 1 2 3 4)
(x= 1 y= 2 z= 3 rest= (4))
> (b 1 2 3 4 5)
(x= 1 y= 2 z= 3 rest= (4 5))
KM
@twoplustwo:matrix.org
[m]
oh yesm of course, I mixed it up ;)
cs7
@cs7:matrix.org
[m]
KM: "." is R5RS, #!rest #!optional #!key is DSSSL = some extension
KM
@twoplustwo:matrix.org
[m]
so there is no need for the extension when I only use rest. is there also a way to use keywords without dsssl ? lets say (define (h1 a #!rest r #!key k) (list a k r)) is this possible?
Marc Feeley
@feeley
> (define (foo x #!key y z . rest) (list 'x= x 'y= y 'z= z 'rest= rest))
> (foo 1)                                                               
(x= 1 y= #f z= #f rest= ())
> (foo 1 z: 2)
(x= 1 y= #f z= 2 rest= ())
> (foo 1 z: 2 y: 3)
(x= 1 y= 3 z= 2 rest= ())
> (foo 1 z: 2 y: 3 4)
(x= 1 y= 3 z= 2 rest= (4))
> (foo 1 z: 2 y: 3 4 5)
(x= 1 y= 3 z= 2 rest= (4 5))
KM
@twoplustwo:matrix.org
[m]
tried it in the repl, this is so cool
cs7
@cs7:matrix.org
[m]
KM: Stuff you learn (that wasn't obvious before you learned it), write it up on the wiki, someone else will probably has the same question later
cs7
@cs7:matrix.org
[m]
:point_up: Edit: KM: Stuff you learn (that wasn't obvious before you learned it), write it up on the wiki, someone else will probably have the same question later
KM
@twoplustwo:matrix.org
[m]
Is there a good way to replace strings in templates, like replace all {{key1}} {{key2}} with value1 valu2 in a string or maybe in a textfile?
Or if not, I could write my own, but how do I find a string position inside another one?
KM
@twoplustwo:matrix.org
[m]
I found this string-contains here https://practical-scheme.net/wiliki/schemexref.cgi?string-contains can I use it somehow?
Marc Feeley
@feeley
@twoplustwo:matrix.org This could be useful:
(define (string-substitute str delim proc-or-alist)

  (define (index-of c start)
    (let loop ((i start))
      (if (fx< i (string-length str))
          (if (char=? c (string-ref str i))
              i
              (loop (fx+ i 1)))
          i)))

  (let loop ((i 0) (j 0) (out '()))
    (let ((start (index-of delim j)))
      (if (fx< start (string-length str))
          (let ((end (index-of delim (fx+ start 1))))
            (if (fx< end (string-length str))
                (if (fx= start (fx- end 1)) ;; two delimiters in a row?
                    (loop (fx+ end 1)
                          (fx+ end 1)
                          (cons (substring str i end)
                                  out))
                    (let* ((var
                            (substring str (fx+ start 1) end))
                           (subst
                            (if (procedure? proc-or-alist)
                                (proc-or-alist var)
                                (let ((x (assoc var proc-or-alist)))
                                  (and x (cdr x))))))
                      (if subst
                          (loop (fx+ end 1)
                                (fx+ end 1)
                                (cons subst
                                        (cons (substring str i start)
                                                out)))
                          (error "Unbound substitution variable in" str))))
                (error "Unbalanced delimiter in" str)))
          (string-concatenate
           (reverse (cons (substring str i start) out)))))))

(pp (string-substitute "@a@ plus 1 is @b@" #\@ '(("a" ."two") ("b" . "three"))))
KM
@twoplustwo:matrix.org
[m]
cool, I will walk through this. how can I import string-concatenate ?
Marc Feeley
@feeley
@twoplustwo:matrix.org string-concatenate is builtin (you need v4.9.4)
cs7
@cs7:matrix.org
[m]
= same as string-append ?
Marc Feeley
@feeley
@twoplustwo:matrix.org (string-concatenate lst) = (apply string-append lst)
cs7
@cs7:matrix.org
[m]
ah yesyes i see. many thanks.
jeffhhk
@jeffhhk

Hello, I'm trying gambit for the first time, starting with the javascript support in 4.9.4. I am able to reproduce the instructions at

http://www.gambitscheme.org/latest/manual/#Compiling-Modules

However, if I change much from that basic scenario, stuff stops working. For example, here is my attempt to extend to importing SRFI 78:

git clone https://github.com/scheme-requests-for-implementation/srfi-78

cat srfi-78/srfi-78.sld
    (define-library (srfi-78)
      (import (scheme base))
      (export hello-world)
      (include "check.scm")
      (begin
        (define (hello-world)
          (display "hello world\n"))
    ))

cat hello-test/hello-test.sld
    (define-library (hello-test)
      (import (srfi-78) (scheme base) (scheme write))
      (begin
        (display
         (cond-expand
           ((compilation-target C)   "compiled to C\n")
           ((compilation-target (_)) "interpreted\n")
           (else                     "compiled to other\n")))
        (hello-world)
        (newline)))

gsc -target js . srfi-78 hello-test
    Building module: srfi-78

gsc -target js . srfi-78
    <no output>
gsc -target js . hello-test
    <no output>

gsc -target js -exe -nopreload . srfi-78/srfi-78.sld hello-test/hello-test.sld
    srfi-78/srfi-78.sld:
    /home/jeff/srchome/src/zipper/srfi-78/srfi-78.js:
    hello-test/hello-test.sld:
    /home/jeff/srchome/src/zipper/hello-test/hello-test.js:
    /home/jeff/srchome/src/zipper/hello-test/hello-test_.js:

hello-test/hello-test
    compiled to other
    *** ERROR IN hello-test# -- Operator is not a PROCEDURE
    (#!void "hello world\n")
I would have expected:
  • two "Building module" messages for building srfi-78 and hello-test together
  • one "Building module" message for building srfi-78 and hello-test each separately
  • successful -exe generation to result in a runnable program.