Rian, you want a syntactic abstraction that hides this mechanism:
#lang racket
(module library racket
(provide
;; syntax
;; (define/safe (f x ...) e ...)
;; introduces a safe function that is ... and prints its name as just 'f'
define/safe)
(define-syntax-rule
(defi
As far as I know, no.
Vincent
At Sun, 5 Jan 2014 19:51:10 -0500,
Rian Shams wrote:
>
> Perfect, I didn't know structs could be used like that.
> Thank you!
>
> As a follow-up question, can you directly create functions with a custom
> printing method, without having to go through structs?
>
>
Perfect, I didn't know structs could be used like that.
Thank you!
As a follow-up question, can you directly create functions with a custom
printing method, without having to go through structs?
On Sat, Jan 4, 2014 at 8:13 PM, Vincent St-Amour wrote:
> Similarly, you can represent safe function
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
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
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
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:
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)
'$*
If I do this I get the results I need for (procedure-arity
(select-random-safe-function)), but when I call
(safe-function-set) or (select-random-safe-function) or any other function
that returns a safe function I get for example:
>(safe-function-set)
'(# # # #)
>(select-random-safe-function)
#
w
Try replacing `safe-function-set` with:
(define safe-function-set (list $+ $- $* $/))
Sam
On Fri, Jan 3, 2014 at 5:28 PM, Rian Shams wrote:
> Hello,
>
> I am working with functions that I have defined to only take 1 or 2 operands
> (called safe-functions) for the implementation of a genetic pro
Hello,
I am working with functions that I have defined to only take 1 or 2
operands (called safe-functions) for the implementation of a genetic
program.
(define ($+ augend addend) ;operation is addition
(+ augend addend)) ; the result is the sum
(define ($- minuend subtrahend) ;operation is sub
11 matches
Mail list logo