LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2012, 01:47 PM   #1
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 183

Rep: Reputation: 15
Common Lisp - "Substringing" numbers?


Hello

Is there anyway of dissecting a number, so i can check the last digit etc. ?

For instance (Pseudocode):
Code:
if last-digit == 8 {
    print "..."
}
if last-digit == 9 {
    print "..."
}
if last-digit < 5 {
    exit
}
 
Old 02-22-2012, 02:22 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Probably the `truncate' function may be of some use here:
Code:
[1]> (setf x 1035)
1035
[2]> (loop do (setf (values x last-digit) (truncate x 10)) (print last-digit) while (/= x 0))

5 
3 
0 
1 
NIL
[3]>
Hope that helps.
 
Old 02-22-2012, 02:53 PM   #3
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 360

Rep: Reputation: 199Reputation: 199
I don't know Lisp, but the idea would be to use integer division and modulo operation by 10, e.g.:

1337 mod 10 -> 7
1337 div 10 mod 10 -> 3

and so on.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lisp: beginner, how to represent "objects" titanium_geek Programming 13 02-01-2010 09:45 AM
Input without pressing "Enter" in Lisp? andrw123 Programming 2 10-15-2008 12:12 AM
FC6: Installer hangs at installing "glibc-common" mgmax Fedora - Installation 4 02-23-2007 11:40 PM
Common problems explained: "kernel panic - not syncing", "unable to mount..." sundialsvcs Linux - Newbie 2 03-01-2006 12:17 PM
How to authorize common-user to run "ifconfig eth0 up"??? cqmyg5 Slackware 2 04-03-2005 11:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration