Re: [racket] racket newbie question on quoting and the built in procedure-arity function

2014-01-04 Thread Vincent St-Amour
Similarly, you can represent safe functions as applicable structures (so they can behave like functions) with a custom printing method. #lang racket (struct safe-function (f name) #:property prop:procedure 0 ; first field is the function #:methods gen:custom-write

Re: [racket] racket newbie question on quoting and the built in procedure-arity function

2014-01-04 Thread Matthias Felleisen
Perhaps you want something like this: Welcome to Racket v6.0.0.1. > (current-print (lambda (x) (if (procedure? x) (printf "~a" (object-name x)) > (print x)) (newline))) # > + + > 10 10 On Jan 4, 2014, at 6:40 PM, Rian Shams wrote: > Sorry for my lack of clarity. > > My question is about t

Re: [racket] Attaching callbacks at runtime?

2014-01-04 Thread Matt Jadud
So obvious. Why I never thought of it, I don't know. Clearly, I was stuck on wondering why there was no setter/getter for the callback field. Just one level of indirection... Cheers, Matt On Sat, Jan 4, 2014 at 5:55 PM, Matthias Felleisen wrote: > > It is trivial to switch the callback's behav

Re: [racket] Attaching callbacks at runtime?

2014-01-04 Thread Matthias Felleisen
It is trivial to switch the callback's behavior at run-time: #lang racket/gui (define f (new frame% [label "test for Matt"])) (define b (new button% [label "hello world"] [parent f] [callback (lambda (b e) (indirect-callback b e))])) (define (cb1 b

Re: [racket] racket newbie question on quoting and the built in procedure-arity function

2014-01-04 Thread Matthias Felleisen
Yes, you need two functions: one that gives you the name of a procedure and one that picks a procedure. I was merely hinting at how to do the former. -- Matthias On Jan 4, 2014, at 4:57 PM, Rian Shams wrote: > Thanks Matthias, > > If I use your definition: > > (define (select-random-safe-f

Re: [racket] choice% - replace all choices

2014-01-04 Thread Matthias Felleisen
On Jan 4, 2014, at 1:30 PM, lothar atheling wrote: > hello, > > is there a way to replace all the choices at one whack? > > i have choice lists several hundred items long, which to reset with > choice% methods clear, append will be tedious > > the only way i can see is to work on a parent ar

[racket] Attaching callbacks at runtime?

2014-01-04 Thread Matt Jadud
Hi all, I've wondered about this for a while, but never asked. When I create a GUI widget, I attach a callback: (define b (new button% [... ...] [callback (lambda (b e) ...)] ...)) Is it possible to attach a callback at runtime? The docs say "no," but I thought I'd ask regardless. Perhaps what

Re: [racket] racket newbie question on quoting and the built in procedure-arity function

2014-01-04 Thread Rian Shams
Thanks Matthias, If I use your definition: (define (select-random-safe-function) (object-name (list-ref safe-function-set (random (length safe-function-set) then, >(procedure-arity (select-random-safe-function)) error:procedure-arity: contract violation expected: procedure? given:

[racket] choice% - replace all choices

2014-01-04 Thread lothar atheling
hello, is there a way to replace all the choices at one whack? i have choice lists several hundred items long, which to reset with choice% methods clear, append will be tedious the only way i can see is to work on a parent area-container% with change-children, but that also looks tedious. it

Re: [racket] procedure to string

2014-01-04 Thread Gustavo Massaccesi
There are more complex closures, that share an external variable. For example: ;- #lang racket (define-values (up! down!) (let () (define counter 0) (define (up!) (set! counter (add1 counter)) counter) (define (down!) (set! counter (sub1 counter)) counter) (values up! down!)))

[racket] Slow things in DrRacket (was: Background expansion off)

2014-01-04 Thread Gustavo Massaccesi
Sorry to hijack the thread. There are two features that I like, but make DrRacket slow. One is the Program Contour. I use it in my desktop computer, but I have to disable it in my netbook. Another one is the rounded highlighting of words in the find/replace window. I usually keep it closed to gai

Re: [racket] racket newbie question on quoting and the built in procedure-arity function

2014-01-04 Thread Matthias Felleisen
If you really just want the name, use object-name: (define (select-random-safe-function) (object-name (list-ref safe-function-set (random (length safe-function-set) Welcome to DrRacket, version 6.0.0.1--2013-12-29(bbb0c5f6/d) [3m]. Language: racket. > (select-random-safe-function) '$*