I was just perusing the "Teach yourself Scheme in fixnum days" tutorial and came across the gambc.scm init section. The tutorial doesn't go into examples of what that file is so I thought I might ask what you all do in the init file.
Bob
Afficher les réponses par date
On 01/10/2009 12:51 PM, Robert H wrote:
I was just perusing the "Teach yourself Scheme in fixnum days" tutorial and came across the gambc.scm init section. The tutorial doesn't go into examples of what that file is so I thought I might ask what you all do in the init file.
Bob
'wrong' is what it is... (At least today)
A 20 second experiment, and subsequent strace run, reveals that it should be ~/.gambcini.scm not ~/gambc.scm.
As for what I have in it (heh), nothing, as I wasn't aware of it either :)
On 1-Oct-09, at 7:57 AM, Nicola Archibald wrote:
On 01/10/2009 12:51 PM, Robert H wrote:
I was just perusing the "Teach yourself Scheme in fixnum days" tutorial and came across the gambc.scm init section. The tutorial doesn't go into examples of what that file is so I thought I might ask what you all do in the init file.
Bob
'wrong' is what it is... (At least today)
A 20 second experiment, and subsequent strace run, reveals that it should be ~/.gambcini.scm not ~/gambc.scm.
As for what I have in it (heh), nothing, as I wasn't aware of it either :)
~/.gambcini.scm is where you should put any commands or definitions (macros or procedures) which you want to have access to from the REPL and other loaded code.
For example, if you want to be able to use syntax-case with no other incantations to gsi then put this in your .gambcini.scm file:
(println "loading ~/.gambcini.scm") (load "~~lib/syntax-case")
If you are a Common Lisp fan and you would like to use "defun" to define functions:
(define-macro (defun name params . body) `(define ,name (lambda ,params ,@body)))
[note that macros defined in .gambcini.scm are available in the REPL and programs loaded from the REPL]
If you constantly need "fib" then add:
(defun fib (n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
etc.
Marc
On 01/10/2009 1:17 PM, Marc Feeley wrote:
On 1-Oct-09, at 7:57 AM, Nicola Archibald wrote:
On 01/10/2009 12:51 PM, Robert H wrote:
I was just perusing the "Teach yourself Scheme in fixnum days" tutorial and came across the gambc.scm init section. The tutorial doesn't go into examples of what that file is so I thought I might ask what you all do in the init file.
Bob
'wrong' is what it is... (At least today)
A 20 second experiment, and subsequent strace run, reveals that it should be ~/.gambcini.scm not ~/gambc.scm.
As for what I have in it (heh), nothing, as I wasn't aware of it either :)
~/.gambcini.scm is where you should put any commands or definitions (macros or procedures) which you want to have access to from the REPL and other loaded code.
For example, if you want to be able to use syntax-case with no other incantations to gsi then put this in your .gambcini.scm file:
(println "loading ~/.gambcini.scm") (load "~~lib/syntax-case")
If you are a Common Lisp fan and you would like to use "defun" to define functions:
(define-macro (defun name params . body) `(define ,name (lambda ,params ,@body)))
[note that macros defined in .gambcini.scm are available in the REPL and programs loaded from the REPL]
If you constantly need "fib" then add:
(defun fib (n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
etc.
Marc
I realised that was the purpose of it, I was correcting the 'init file' of ~/gambc.scm that TYSiFD states, as Robert was quoting...
While we're on the subject though, I notice that ~/.gambcini.scm gets compiled *before* any command line parameters - thus rendering it 'awkward' for blackhole users, since anything defined in it has to explicitly put in the "~" namespace...
Wouldn't it make more sense for it to be executed after command line parameters? Or am I missing something?
(As for your example of defun, I wouldn't do that, but I am partial to lisp's 'nth' function and find myself defining that an awful lot, so I've put it in the ini file for now :)
On 1-Oct-09, at 8:24 AM, Nicola Archibald wrote:
While we're on the subject though, I notice that ~/.gambcini.scm gets compiled *before* any command line parameters - thus rendering it 'awkward' for blackhole users, since anything defined in it has to explicitly put in the "~" namespace...
If I remember correctly, blackhole is "loaded" from a command line "- e" argument. That's not a good integration. It would be better to start it from the ~~lib/gambcext file, which is another customization file that is loaded before ~/.gambcini . Here is the relevant part of the documentation:
There are two ways to customize the interpreter. When the interpreter starts off it tries to execute a @samp{(load "~~lib/gambcext")} (for an explanation of how file names are interpreted see @ref{Host environment}). An error is not signaled when the file does not exist. Interpreter extensions and patches that are meant to apply to all users and all modes should go in that file.
Marc
If I remember correctly, blackhole is "loaded" from a command line "- e" argument. That's not a good integration. It would be better to start it from the ~~lib/gambcext file, which is another customization file that is loaded before ~/.gambcini . Here is the relevant part of the documentation:
Thanks for the info.
Yes, at the moment blackhole is loaded using a "-e" command line argument. I didn't know any other way of doing it. When I get the time I'll try using ~~lib/gamcext. Loading blackhole is not a complex process at all, it is simply loaded using the |load| procedure.
/Per
On 02/10/2009 2:53 PM, Per Eckerdal wrote:
If I remember correctly, blackhole is "loaded" from a command line "- e" argument. That's not a good integration. It would be better to start it from the ~~lib/gambcext file, which is another customization file that is loaded before ~/.gambcini . Here is the relevant part of the documentation:
Thanks for the info.
Yes, at the moment blackhole is loaded using a "-e" command line argument. I didn't know any other way of doing it. When I get the time I'll try using ~~lib/gamcext. Loading blackhole is not a complex process at all, it is simply loaded using the |load| procedure.
/Per
I found a nice way of implementing loading blackhole via the extensions init file, and still having a seperate bsc/gsc command pair, by symbolically linking bsc -> gsc, and putting:
(if (equal? (car (command-line)) "bsc") (and (load "~~/lib/modules/build") (display "loaded blackhole extensions...") (newline)) #!void)
In my /usr/local/Gambit-C/lib/gambcext file.
This would probably need some tweaking to work on windows platforms (probably just checking if it starts with 'bsc' and ignoring case, then copy gsc.exe to bsc.exe would work).
The advantage of this is that I still get the gsc header message - it's always bugged me a little that the 'normal' way of defining bsc meant you didn't see the version info of gambit, it bit me once when i had 4.5.0 and 4.5.1 installed in slightly different places, both with a blackhole system installed (in one case, woefully out of date). Also I can see at a glance that blackhole is listed by the display message in the load process.
To be honest, since I use bsc/blackhole 100% of the time on my install, I'm starting to wonder if there is really any benefit to having a seperate bsc/gsc pair of commands though - at least in my personal case.
I found a nice way of implementing loading blackhole via the extensions init file, and still having a seperate bsc/gsc command pair, by symbolically linking bsc -> gsc, and putting:
(if (equal? (car (command-line)) "bsc") (and (load "~~/lib/modules/build") (display "loaded blackhole extensions...") (newline)) #!void)
In my /usr/local/Gambit-C/lib/gambcext file.
That's really neat! I would write it like this:
(and (equal? (car (command-line)) "bsc") (load "~~lib/modules/build") (let () (##namespace ("module#")) (##include "~~lib/gambit#.scm")
(println "Loaded Black Hole...")))
This leaves room for users to add custom load-time configuration, for instance
(and (equal? (car (command-line)) "bsc") (load "~~lib/modules/build") (let () (##namespace ("module#")) (##include "~~lib/gambit#.scm")
(module-resolver-add! 'user (package-module-resolver "~/.blackhole"))
(println "Loaded Black Hole...")))
What do you think?
/Per
2009/10/6 Per Eckerdal per.eckerdal@gmail.com:
(if (equal? (car (command-line)) "bsc") (and (load "~~/lib/modules/build") (display "loaded blackhole extensions...") (newline)) #!void)
Ummm
What do you think?
That his version may not behave as expected the day that DISPLAY returns #f (which is correct, as DISPLAY is returns an undefined value, IIRC) Also, load's semantics are not to be found in the documentation (testing suggests it returns a string in successful cases, and an error otherwise), so using it in an AND seems bug prone.
P!