Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

converting words to numbers?
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 :)


Report this thread to moderator Post Follow-up to this message
Old Post
Mephistopheles
12-14-04 02:02 AM


Re: converting words to numbers?
"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.

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Harvey
12-14-04 02:02 AM


Re: converting words to numbers?
The point is that i must write it in scheme not C.A bet without a border is
meanless.


Report this thread to moderator Post Follow-up to this message
Old Post
Mephistopheles
12-14-04 02:02 AM


Re: converting words to numbers?
"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.

Report this thread to moderator Post Follow-up to this message
Old Post
Pascal Bourguignon
12-14-04 02:02 AM


Re: converting words to numbers?
"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.

Report this thread to moderator Post Follow-up to this message
Old Post
Pascal Bourguignon
12-14-04 02:02 AM


Re: converting words to numbers?
Thanks 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Mephistopheles
12-14-04 02:02 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:45 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.