It is now clear me that Racket is more than rich enough to make for an elegant representation and the handling of functions will be key to this.I don't know if you've studied MIT-Scheme at all, but there they have a form called the named-lambda, which implements lambda. That idea may be of some use. Or something like it. Or something not at all like it. Who knows?Here is named-lambda for Racket.#lang racket/base(require (for-syntax racket/base syntax/parse syntax/parse/lib/function-header))(define-syntax (named-lambda stx)(syntax-parse stx[(_named-lambda (f:id . args:formals) b ...)(syntax/loc stx(procedure-rename (λ args b ...) 'f))]))(named-lambda (foo x [y 2]) (list x y))((named-lambda (foo x [y 2]) (list x y)) 1)((named-lambda (foo x [y 2]) (list x y)) 1 3)
The output is:#<procedure:foo>'(1 2)'(1 3)The function object-name is used by the printer to extract the name from the procedure.You can also attach object names to structure values - use the property prop:object-name./Jens Axel
Alex wrote: |
From the documentation ... |
Here is named-lambda for Racket.
#lang racket(require mathracket/structracket/base;; syntax stufffor-syntaxsyntax/parsesyntax/parse/lib/function-header);; for function name experimantation
(define-syntax (named-lambda stx)(syntax-parse stx[(_named-lambda (f:id . args:formals) b ...)(syntax/loc stx(procedure-rename (λ args b ...) 'f))]))
; ================================================
Welcome to DrRacket, version 6.3 [3m].Language: racket; memory limit: 512 MB.. standard-module-name-resolver: collection not foundfor module path: for-syntaxcollection: "for-syntax"in collection directories:/home/alex/.racket/6.3/collects/usr/share/racket/collects... [163 additional linked and package directories] in: for-syntaxno packages suggestions are available .>
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> (let ((pol1 (lambda(x) (+ (* x x) (* -2 x) 1)))(pol2 (lambda(x) (- (* x x) 1))))((/ pol1 pol2) 'x))#|(/ (+ -1 x) (+ 1 x))|#
scheme@(guile-user)> (math)type qed; to return to scheme, type help; for help.e2 : (x^2 - 2*x + 1) / (x^2 -1);-1 + xe2: ------1 + xe3 : qed;$13 = schemescheme@(guile-user) >
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
BTW, the Guile environment provides two forms lambda* and define*, which are documented here. basically they are just lambda and define, allowing for a whole lot more arguments. Does the Racket world have something like this already, or will I have to write the syntaxes for them?
Welcome to DrRacket, version 6.12 [3m].Language: racket, with debugging; memory limit: 256 MB.> (define unity (g:+ (g:square sin)(g:square cos)))> (unity 42)1.0>
The rest shouldn't be as much of a headache...
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.