This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How to make a scheme program accept inputs

2 posts · 2631 views

I have the following program
(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

Re: How to make a scheme program accept inputs

So imagine you have code as an expression that takes data:
(some-processexpression some-otherargument data1 data2)
You can always make a true refactoring by wrapping it in a fucntion and call it instead:
(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