sorry for asking a PLT-specific question here, but what is the best way
to have functions and macro definitions from some file available in
addition to the features found in some language like "Pretty Big" or
"R5RS"?
Thank you,
Nicolas
#lang scheme
You can also use `(#%require "something")' if you really insist on
using the R5RS lanuguage.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!
> Grant Rettke <gre...@gmail.com> writes:
>
>> On May 26, 9:21�am, Nicolas Neuss <lastn...@kit.edu> wrote:
>>> sorry for asking a PLT-specific question here, but what is the best way
>>> to have functions and macro definitions from some file available in
>>> addition to the features found in some language like "Pretty Big" or
>>> "R5RS"?
>>
>> #lang scheme
>
> You can also use `(#%require "something")' if you really insist on
> using the R5RS lanuguage.
Probably I was not clear enough. At the moment I use PLT Scheme inside
a course which is partially me teaching and partially students solving
some tasks. Now, I want certain utility functions which we have
developped until now to be available for the next session. At the
moment, I see the possibility to put them in a file, say "useful.scm",
and put
(load "useful.scm")
at the beginning of the (initially empty) file for the next session. Is
this the prefered method?
[Aside: I am thinking about using also a Greek lambda for the word
lambda by defining a suitable syntax-rules macro. What experiences do
people here have with this? Is it worthwhile?]
Nicolas
Well, to type letters in non-roman scripts, I have bound commands to
set the input method to gree, (and hebrew and russian) on C-F10,
C-F11, C-F12. So I can type these letters easily, but when I have
only one letter to type in the middle of roman text, I have to type:
C-F11 l C-\
That's five keypresses. lambda is six key presses, and closer to the
home row.
In this context, it is not worthwhile.
On the other hand, it's nice to have emacs displaying all occurences
of the name of a greek letter as a greek letter, so as soon as I type
lambda, it displays it as λ.
Then I can also write:
(define (iota n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
(iota 10)
(define (SIGMA min max fun)
(if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
(SIGMA 1 10 (lambda (x) (* x x)))
and see:
(define (ι n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
(ι 10)
(define (Σ min max fun)
(if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
(Σ 1 10 (λ (x) (* x x)))
Of course, if I wanted or needed to type λ more often, I could as well
bind it to an easier key or key-chord. Which I actually did,
recently, when I had to revise my ~/.Xmodmap. I mapped AltGr- keys to
greek letters and mathematical symbols, so that I can 'easily' write
stuff like:
∀(α,β)∈N² ∃Θ∈P(N), α≤β ⇒ [α,β]∩Θ=∅ ∨ [α,β]⊂Θ
--
__Pascal Bourguignon__ http://www.informatimago.com/
> Eli Barzilay <e...@barzilay.org> writes:
>
>> Grant Rettke <gre...@gmail.com> writes:
>>
>>> On May 26, 9:21 am, Nicolas Neuss <lastn...@kit.edu> wrote:
>>>> sorry for asking a PLT-specific question here, but what is the best way
>>>> to have functions and macro definitions from some file available in
>>>> addition to the features found in some language like "Pretty Big" or
>>>> "R5RS"?
>>>
>>> #lang scheme
>>
>> You can also use `(#%require "something")' if you really insist on
>> using the R5RS lanuguage.
>
> Probably I was not clear enough. At the moment I use PLT Scheme
> inside a course which is partially me teaching and partially
> students solving some tasks. Now, I want certain utility functions
> which we have developped until now to be available for the next
> session. At the moment, I see the possibility to put them in a
> file, say "useful.scm", and put
>
> (load "useful.scm")
>
> at the beginning of the (initially empty) file for the next session.
> Is this the prefered method?
It is generally much better to use a module system. (IMO, YMMV, etc.)
Specifically, if you really want to use `load', then you should avoid
`#lang' which will make the file be a module. (But I can only repeat
that `load' can be a really bad idea.)
> [Aside: I am thinking about using also a Greek lambda for the word
> lambda by defining a suitable syntax-rules macro. What experiences
> do people here have with this? Is it worthwhile?]
In the PLT `#lang scheme' language, `λ' is already has the same
binding as `lambda'. If you want it in R5RS, defining it yourself is
easy:
(define-syntax λ
(syntax-rules () ((λ . stuff) (lambda . stuff))))
I don't remember if Emacs was specified as a requirement, but in
DrScheme you get a `λ' with C-\. You can also type in other greek
characters using M-\ like this: type "\name" (eg, backslash followed
by "alpha"), and then M-\ will replace that with "α".
> On the other hand, it's nice to have emacs displaying all occurences
> of the name of a greek letter as a greek letter, so as soon as I
> type lambda, it displays it as λ.
PLT works fine with unicode, so it is possible to just do things like:
(define (ι n) (if (< 0 n) (append (ι (- n 1)) (list n)) (list 0)))
(ι 10)
(define (Σ min max fun)
(if (< min max) (+ (fun min) (Σ (+ 1 min) max fun)) 0))
(Σ 1 10 (λ (x) (* x x)))
(Your original snip had `ι' as the defined name, and `iota' as the
recursive call, and the same typo in `Σ'.)
> It is generally much better to use a module system. (IMO, YMMV, etc.)
> Specifically, if you really want to use `load', then you should avoid
> `#lang' which will make the file be a module. (But I can only repeat
> that `load' can be a really bad idea.)
OK, I'll try to make it run as a module.
>> [Aside: I am thinking about using also a Greek lambda for the word
>> lambda by defining a suitable syntax-rules macro. What experiences
>> do people here have with this? Is it worthwhile?]
>
> In the PLT `#lang scheme' language, `锟斤拷' is already has the same
> binding as `lambda'.
Nice! I think this makes much sense for teaching functional
programming.
> If you want it in R5RS, defining it yourself is
> easy:
>
> (define-syntax 锟斤拷
> (syntax-rules () ((锟斤拷 . stuff) (lambda . stuff))))
Yes, I had tried that already (with ". stuff" replaced by "(arg ...)
body ...").
Thank you,
Nicolas
> [...]
> On the other hand, it's nice to have emacs displaying all occurences
> of the name of a greek letter as a greek letter, so as soon as I type
> lambda, it displays it as 锟斤拷.
>
> Then I can also write:
>
> (define (iota n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
> (iota 10)
> (define (SIGMA min max fun)
> (if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
> (SIGMA 1 10 (lambda (x) (* x x)))
>
> and see:
>
> (define (锟斤拷 n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
> (锟斤拷 10)
> (define (锟斤拷 min max fun)
> (if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
> (锟斤拷 1 10 (锟斤拷 (x) (* x x)))
Do you have Elisp code doing this? I think it would be a nice SLIME
addition.
Thanks,
Nicolas
> p...@informatimago.com (Pascal J. Bourguignon) writes:
>
>> [...]
>> On the other hand, it's nice to have emacs displaying all occurences
>> of the name of a greek letter as a greek letter, so as soon as I type
>> lambda, it displays it as λ.
>>
>> Then I can also write:
>>
>> (define (iota n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
>> (iota 10)
>> (define (SIGMA min max fun)
>> (if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
>> (SIGMA 1 10 (lambda (x) (* x x)))
>>
>> and see:
>>
>> (define (ι n) (if (< 0 n) (append (iota (- n 1)) (list n)) (list 0)))
>> (ι 10)
>> (define (Σ min max fun)
>> (if (< min max) (+ (fun min) (SIGMA (+ 1 min) max fun)) 0))
>> (Σ 1 10 (λ (x) (* x x)))
>
> Do you have Elisp code doing this? I think it would be a nice SLIME
> addition.
Yes. See: greek-letter-font-lock and around in:
http://tinyurl.com/3x3l86f (pjb-sources.el)
Note: I've not updated for emacs-23, where the encoding of characters
or something has changed.
OK, I've managed to extract the code and make it run with Emacs 23, see
<http://ruprecht.mathematik.uni-karlsruhe.de/misc/greek.el> (I think the
important change was to take out "terminalsigma".)
I'm in doubt, if I like it, though, because the single lambda character
does not stand out as much as the highlighted "lambda". (In DrScheme,
the lambda symbol is very large, so that might work out better.)
Nicolas