Tuesday, June 30, 2009

ruby-fying scheme

So, I was reviewing ID3A and realized that there was a potential usage (mostly for myself) to port it into PocketScheme for my ipaq.

Then, I hit upon the brick wall that is string manipulation (or lack thereof) in Scheme.
For example, there is no String.reverse equivalent (hint: convert it to a list, then reverse, then back to a string) so I thought I would begin my porting all of my favourite Ruby commands over to Scheme.

First up: Array.join => list-join


; list-join works the same way that Array.join in ruby works
; in other words, take an array and make a delimited string
; "one,two,three"
; a simple way to build strings for file output
; x-> list
; y-> delimiter (must be a char)
(define (list-join x y)
(define o (open-output-string))
(let iter (( i 0 ))
(if (= i (length x)) (newline)
(begin
(display (list-ref x i) o)
(if (< i (- (length x) 1)) (write-char y o))
(iter (+ i 1)
)
)
)
)
(get-output-string o)
)

Sunday, June 28, 2009

Scheme Goodness

But after several months of fighting in my spare time with getting the eVB up and running on my virtualised XP system, I just gave up and figured that this blog would not really go anywhere interesting.

Until, I chanced upon the fact that PocketScheme has the hooks in it to generate and deal with actual WindowsCE forms.

Of course, it's as ugly as writing windowed apps in C but, hey - it's Scheme for pete's sake. One should be able to abstract much of that ugliness that is windowed apps in C. (*shudder)

Here's a taste of some Scheme goodness in a simple app that adds two to a number you give it:

(begin
(define (x n) (+ 2 n))
(display "enter a number:")
(define mynum (read))
(define res (x mynum))
(display #\newline)
(display "result:")
(display "res)
)