Code Comments
Programming Forum and web based access to our favorite programming groups.Hello,i'm a newbie in scheme :) I have a bet with my friends.Thus; I have to write a prog. which will convert words to numbers,for eg: (convert 'fivethousandthreehundredten) => 5310 But i shouldnt use recursion and the word which will be converted must have not spaces like five thousand ...... Please help me and i can earn a few bucks from my friends :)
Post Follow-up to this message"Mephistopheles" <mephistopheles@superonline.com> writes: >But i shouldnt use recursion This is sort of like betting you could write the program in Smalltalk and not use objects: maybe it's possible, but what's the point? You might as well write it in C.
Post Follow-up to this messageThe point is that i must write it in scheme not C.A bet without a border is meanless.
Post Follow-up to this message"Mephistopheles" <mephistopheles@superonline.com> writes: > Hello,i'm a newbie in scheme :) > I have a bet with my friends.Thus; > I have to write a prog. which will convert words to numbers,for eg: > (convert 'fivethousandthreehundredten) > => 5310 > > But i shouldnt use recursion and the word which will be converted must > have > not spaces like five thousand ...... > > Please help me and i can earn a few bucks from my friends :) You could insipire you from this Common Lisp joke of mine, adding a filter to remove spaces and punctuation: (defun nl-string-to-number (text) ;; Of course, you could program it more intelligently and more efficiently. (do* ((i 0 (1+ i)) (s (format nil "~r" i) (format nil "~r" i))) ((or (string-equal s text) (< (* 2 (length text)) (length s))) (when (string-equal s text) i)))) (defmacro def-s-op (name num-op) `(defun ,name (&rest args) (format nil "~r" (apply (function ,num-op) (mapcar (function nl-string-to-number) args))))) (def-s-op +s +) (def-s-op -s -) (def-s-op *s *) (def-s-op /s /) (def-s-op =s =) (def-s-op /=s /=) (def-s-op <s < ) (def-s-op <=s <=) (def-s-op >s > ) (def-s-op =>s <=) (-s "one" "two") -- __Pascal Bourguignon__ http://www.informatimago.com/ The world will now reboot; don't bother saving your artefacts.
Post Follow-up to this message"Mephistopheles" <mephistopheles@superonline.com> writes: > The point is that i must write it in scheme not C.A bet without a border i s > meanless. But since the scheme compiler will remove the tail recusion, you'd just have to provide your code disassembled to show an iterative solution. When the border is the universe, it's meaningless all the same. -- __Pascal Bourguignon__ http://www.informatimago.com/ The world will now reboot; don't bother saving your artefacts.
Post Follow-up to this messageThanks Pascal for these complicated things :) hmm but i must say it again : i'm a newbie in scheme.These useful things that you wrote, seems fantastical far away to me.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.