Discussion of Scheme and Racket
-
vitomzev
- Posts: 3
- Joined: Tue Nov 07, 2017 12:56 am
Post
by vitomzev » Sat Nov 11, 2017 3:58 am
I have the following program
Code: Select all
(define (cat . nums) (apply string-append (map number->string nums)))
(define (my-compare a b) (string>? (cat a b) (cat b a)))
(map (lambda (xs) (string->number (apply cat (sort xs my-compare))))
'((1 34 3 98 9 76 45 4) (54 546 548 60)))
and I would like it to accept inputs, that I type for example: (my-function '((1 34 3 98 9 76 45 4) (54 546 548 60)))
and then it executes the program and outputs the result
Thanks in advance
-
sylwester
- Posts: 133
- Joined: Mon Jul 11, 2011 2:53 pm
Post
by sylwester » Thu Nov 16, 2017 2:28 pm
So imagine you have code as an expression that takes data:
Code: Select all
(some-processexpression some-otherargument data1 data2)
You can always make a true refactoring by wrapping it in a fucntion and call it instead:
Code: Select all
(define (my-abstraction-name arg1 arg2)
(some-processexpression some-otherargument arg1 arg2))
;; call the abstraction instead:
(my-abstraction-name data1 data2)
These are identical programs. The reason is that you can always replace a procedure call with it-s body and replacing the bound variables for their evaluated argument.
I'm the author of
two useless languages that uses
BF as target machine.
Currently I'm planning a Scheme compiler :p