Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 19 17:59
    fare opened #659
  • Jan 14 23:42
    gambiteer commented on ca8b488
  • Jan 14 22:02
    Windows-mingw build of CI run 486454730 failed
  • Jan 14 21:37

    gambiteer on master

    Speed up implementation of SRFI… (compare)

  • Jan 12 16:17
    feeley commented #658
  • Jan 12 16:11
    jcubic commented #658
  • Jan 12 15:48
    feeley commented #658
  • Jan 12 15:30
    feeley closed #658
  • Jan 12 15:30
    feeley commented #658
  • Jan 12 14:10
    jcubic opened #658
  • Jan 09 18:35
    feeley closed #657
  • Jan 09 18:35
    feeley commented #657
  • Jan 09 15:28
    jcubic opened #657
  • Jan 09 14:42
    Windows-mingw build of CI run 474136150 failed
  • Jan 09 14:15

    feeley on master

    Universal backend: add URL whit… (compare)

  • Jan 08 21:28
    feeley commented #655
  • Jan 08 20:48
    lassik commented #655
  • Jan 08 08:00
    jcubic commented #655
  • Jan 08 07:59
    jcubic commented #655
  • Jan 08 02:00
    Windows-mingw build of CI run 470488801 failed
Marc Feeley
@feeley
yes exactly... but now primitives can be added gradually and at all moments the code works but "faster" (hopefully!)
Jaime Fournier
@ober
@feeley is there any sort of inspect/documentation/describe features to return the doc string for a given function?
Marc Feeley
@feeley
@ober The closest thing is (help open-process) but that is to access the Gambit manual.
Jaime Fournier
@ober
ok thank you
Marc Feeley
@feeley
@ober It shouldn't be too hard to add a wrapper to do this.
Marc Feeley
@feeley
For example this code (you need to compile it):
(define (attach-docstring docstring proc)
  (lambda args
    (##first-argument docstring)
    (apply proc args)))

(define docstring-closure (attach-docstring "" list))

(define (get-docstring proc)
  (and (##closure? proc)
       (eq? (##closure-code proc)
            (##closure-code docstring-closure))
       (##closure-ref proc 1)))

(define hello
  (attach-docstring
   "hello is a neat function"
   (lambda (who)
     (println "hello " who "!"))))

(pp (get-docstring car))   ;; prints #f
(pp (get-docstring hello)) ;; prints "hello is a neat function"

(hello "world")
Jaime Fournier
@ober
nice ty
Jaime Fournier
@ober
@feeley almost done with a homebrew entry for gambit-scheme
Jaime Fournier
@ober
brew install https://github.com/ober/gerbil/blob/master/brew/gambit-scheme.rb works on 10.11. and 10.14
Bradley Lucier
@gambiteer
@ober: Cool! A recent commit recommends not using '--enable-c-opt --enable-gcc-opts' in general-use situations. Maybe you want to remove these options for a general homebrew install: gambit/gambit@e423b54
Jaime Fournier
@ober
@gambiteer yeah, using it as this build is to facilitate gerbil. will clean it up. thanks for the feedback
Marc Feeley
@feeley
@ober Also... the newer build process is to do a simple "make" after the "./configure" (no need for the "make bootstrap")
Jaime Fournier
@ober
@feeley cool
Pavel R.
@proksi21
@feeley Where can I read about alternative Gambit backends (like JS)?
Marc Feeley
@feeley
@proksi21 unfortunately the alternative backends are not documented in the manual, in part because they are not ready for production use... you will find some information on the Gambit list.
Dan
@atstp
Would there be interest in some documentation contributions? I've been following gambit development from the sidelines for a while and would be interested in getting a bit more involved (assuming it would be considered useful).
Bradley Lucier
@gambiteer
@atstp YES, YES, YES!
Marc-André Bélanger
@belmarca
@atstp yes...
Dan
@atstp

glad to hear it! is there anything that's already been identified as a need or want?

I have some thoughts, but they're all from a new-to-gambit perspective. I'd imagine there's stuff you all work on regularly that I've never heard of (e.g., the r7rs modules mentioned above).

Marc-André Bélanger
@belmarca
I'd be interested in reading anything about the universal backend...
Dan
@atstp
Me as well, regardless of its production readiness
Also, to anyone who can address it, gambitscheme.org looks to be down.
Dan
@atstp

some stuff I would be happy to work on:

  • alternative-backend docs/articles
  • more examples (anything from vanilla scheme to gambit extensions to backend-specific code)
  • R7RS support docs/articles
  • try-in-browser (or just make this more available)
  • a simple, curated static site would make a huge difference (in my opinion) when it comes to introducing gambit. It's tough for a newcomer to find current, cohesive information outside of the manual.

Does anything there sound like its worth prioritizing? Does any of it not align with the goals of gambit?

Marc Feeley
@feeley
@atstp I would greatly appreciate some help with improving the documentation which is currently a bit outdated. One place to start would be to document all the currently undocumented procedures of Gambit's runtime library. The universal backend would also warrant a section in the manual. Tutorials would also be good, probably best on a web site such as gambitscheme.org .
Marc Feeley
@feeley

@belmarca Here is are some quick instructions if you want to give the universal backend a try. The PHP and Java backends seem to have suffered from bit-rot, but the JavaScript, Python and Ruby backends seem to be still working on v4.9.0 . Here's how to compile a simple hello world. From the root of the Gambit source directory, after a successful "make":

% cd lib
% make _gambit.js
% make _gambit.py
% make _gambit.rb
% cd ..

This builds the Gambit runtime library for JavaScript, Python and Ruby. Then to compile a program for a specific backend you add the -target <BACKEND> option when invoking gsc, where <BACKEND> is js, python or ruby. Here's an example for JavaScript:

% cat test.scm
(println "hello!")
% gsc/gsc -:=. -target js -exe test.scm
% ./test
hello!

Note that the file test is a shell script that starts nodejs to run the script. The script for this program is 15Mbytes and almost 500K lines of JavaScript code! It's this big because all of the Gambit runtime library is included in the file test. For example bignums and pretty-printing are available:

% cat test.scm
;; print sqrt of 2 to 50 decimal places
(pp (integer-sqrt (* 2 (expt 10 100))))
% gsc/gsc -:=. -target js -exe test.scm
% ./test
141421356237309504880168872420969807856967187537694

One way to get a smaller footprint it to write you own runtime library. Here's a minimal runtime library for JavaScript that only defines the console.log procedure:

% cat test.scm
(console.log "hello!")
% cat rts.scm
(declare (extended-bindings) (not safe))

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

;; run each linked module (except for this file)
(let ((module-descrs (##vector-ref ##program-descr 0)))
  (let loop ((i 1))
    (if (##fx< i (##vector-length module-descrs))
        (begin
          ((##vector-ref (##vector-ref module-descrs i) 1))
          (loop (##fx+ i 1))))))
% gsc/gsc -:=. -target js -c rts.scm
% gsc/gsc -:=. -target js -link -l rts.js test.scm
% cat test_.js test.js rts.js > app.js
% node app.js
hello!
% wc app.js
     768    2238   18107 app.js

It is much smaller at 768 lines of code. Although you get a minimal runtime library, this may be a good approach to use Scheme code in a Web page with a minimal footprint.

Marc-André Bélanger
@belmarca
@feeley Thank you :)
Pavel R.
@proksi21
@feeley does gambit support cross compilation?
I'm looking for the best way to create static executable for ARM, using my x86_64 Linux laptop.
Marc Feeley
@feeley
@proksi21 Yes Gambit supports cross compilation but not "out of the box". The Gambit compiler outputs portable C code that can be compiled on any platform (32 or 64 bit) with a decent C compiler. However the configure script assumes that it can use the configured C compiler to compile and execute small code snippets to determine basic characteristics of the C compiler, in particular to create include/gambit.h from include/gambit.h.in . So maybe you will have to do some of these steps manually, or modify the configure script to support cross compilation. Also, if you want .o1 files and executables generated with the -exe option to be properly compiled you will have to tweak the first few lines of the bin/gambcomp-C script which is executed by gsc.
Pavel R.
@proksi21
So, if I compile generated C code manually for target architecture, do I need to manually link any additional libs?
Marc Feeley
@feeley

The Gambit runtime library (in the lib directory) must also be compiled for your target platform. The C code generated by the Gambit compiler for your app must then be linked with the Gambit runtime library. A good way to understand the required low-level steps is to pass the -verbose option to gsc. It will show the invocations of the C compiler. For example, if "app.scm" contains your program:

% gsc -exe -verbose app.scm
Parsing:
  "expr"

Compiling:

Dumping:
  #<primitive app#>

Compilation finished.
gcc  -O1    -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common   -D___SINGLE_HOST  -I"/Library/Gambit/v4.9.0/include" -c -o "app.o"  app.c
gcc  -O1    -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common   -D___SINGLE_HOST  -I"/Library/Gambit/v4.9.0/include" -c -o "app_.o"  app_.c
gcc     -Wno-unused -Wno-write-strings -Wdisabled-optimization -fwrapv -fno-strict-aliasing -fno-math-errno -fomit-frame-pointer -fPIC -fno-common    -D___SINGLE_HOST  -I"/Library/Gambit/v4.9.0/include"  -o "app"   app_.o app.o "/Library/Gambit/v4.9.0/lib/libgambit.a"

As you can see the last step links the executable with libgambit.a, the Gambit runtime library. It is the Gambit runtime library that contains the GC and the interface to the operating system (for file I/O, networking, time, etc).

Jaime Fournier
@ober
exactly what I was looking for thanks
Marc Feeley
@feeley
To get started, you should use the --enable-ansi-c configure option that forces the Gambit runtime system to only use (and be linked to) functions provided by ANSI-C (https://www.cs.auckland.ac.nz/references/unix/digital/AQTLTBTE/DOCU_085.HTM). This is pretty "bare-bones" as it will disable many features (such as networking, subprocesses, etc) but it is a good approach to get started quickly. After that works, you can enable more advanced features to see which features work on the target platform (see include/config.h).
Flynn Liu
@flynn16
Does Gambit have pattern matching built in? (something like racket/match)?
Marc Feeley
@feeley
There's no built in match facility, but it isn't that hard to write one (I have one that I use when I need that).
Jaime Fournier
@ober
gerbil has it added on top right?
ben.txt
@bentxt
@Liu thanks for that question, I too are interested in a match.scm library, that is compatible with gambit
Pavel R.
@proksi21
@feeley hey Mark, I still have some troubles with manual compiling of produced .c files. I'm not very skilled in C. Can you write a simple step-by-step example, to see what exactly I should do to produce files on Linux machine, that I can later compile on another machine with gcc (or clang)?
Marc Feeley
@feeley
@bentxt I'll add the match library to the repo once I've cleaned it up.
@proksi21 Sure, but you can also look at misc/vcexpress.bat to get the general idea.
nortiero
@nortiero

Hi! Is there a way to generate scheme objects out of C constant values? That's what I'm currently doing:

(define-macro (c-const-return name c-type c-value)
  (let ((acstring (eval `(string-append "___return(" ,c-value ");" ))))
    `(begin
       (##define ,name #f)
       (##set! ,name ((c-lambda () ,c-type ,acstring))))))

(c-const-return urE_KEYDOWN ur-stringhash "E_KEYDOWN")       ;; const
(c-const-return urP_KEY int "KeyDown::P_KEY")  ;; const too

This is somewhat cumbersome, the resulting routines -- a couple thousand in my humble case -- will never be optimized away by compiler.
It works well, but not fast and prone to code bloat. C #defines, enums and C++ const T values are well known at compile time .. is there a way to inject the relevant macros inside Gambit's C product ? e.g. something like (c-initialize " ___NEW_SCMOBJ(foobaz, int, KeyDown::P_KEY);") or even better a (define foobaz (c-import int "KeyDown::P_KeY")) ?
Sorry if I am asking something obvious and thanks for all the fish!

Marc Feeley
@feeley
@proksi21 I have made a hello-world app to show the steps of the process. You should get the source code from http://www.iro.umontreal.ca/~feeley/app.tar.gz then untar it, cd app and ./build . This will build the executable a.out that prints "hello world!". Just replace the files hw.c and hw_.c by the files generated with "gsc -link myapp.scm" and it should work (but you will probably have to tweak the "build" script for advanced features like networking, threads, etc).
Pavel R.
@proksi21
@feeley I get the following error:
lib/setup.o: In function ___trunc': setup.c:(.text+0x2139): undefined reference tofloor'
Seems like I should link math.h somewhere
Marc Feeley
@feeley

@proksi21 What is the last gcc command executed that leads to that error? The build script I wrote contains:

C_COMPILE_TO_EXE="$C_COMPILER -Iinclude -o $EXE_NAME -lm"

Which links with the math library (the -lm at the end).

Pavel R.
@proksi21
@feeley Let me check
gcc -Iinclude -o a.out lib/main.o lib/setup.o lib/mem.o lib/os_setup.o lib/os_base.o lib/os_thread.o lib/os_time.o lib/os_shell.o lib/os_files.o lib/os_dyn.o lib/os_tty.o lib/os_io.o lib/c_intf.o lib/actlog.o lib/_kernel.o lib/_system.o lib/_num.o lib/_std.o lib/_eval.o lib/_io.o lib/_nonstd.o lib/_thread.o lib/_repl.o lib/_gambit.o hw.c hw_.c
Nope, in your script:
C_COMPILE_TO_EXE="$C_COMPILER -Iinclude -o $EXE_NAME"
Marc Feeley
@feeley
Then please add the -lm . Somehow I uploaded a previous script.
Pavel R.
@proksi21
The same error with -lm flag added
Marc Feeley
@feeley
Can you check the last gcc command again? Is the -lm there?