From: Hans3 <tomkorver@gm...>  20070121 23:25:34

Hi, Im a LISP beginner and I would like some help. I have 2 problems that might be easy for an advanced programmer: 1. A function which will interpolate the values of 2 lists in a number of steps, so '(1 1 1 1 1) and '(0.5 1 1.5 2 3) would become: ( 1.000 1.000 1.000 1.000 1.000 0.875 1.000 1.125 1.250 1.500 0.750 1.000 1.250 1.500 2.000 0.625 1.000 1.375 1.750 2.500 0.500 1.000 1.500 2.000 3.000 ) How do I make this? 2. A function that returns a list containing integers between sets of lower and upper boundaries. For example: function 20 26 23 28 would return: (20 21 22 23 24 25 26 27 28) Any even number should be possible. 3. A random generator that chooses values form a list or a stackpile without repeating any values until all have been used once. 4. A random generator that chooses values form a list or a stackpile with a specific weight. Example: (weight '(1 2 3) '(4 2 1)) means that 1 has a weight of 4, 2 has a weight of 2 and 3 has a weight of 1, so 1 will be twice as much in a list that 2 and so on. I would grately appreciate if anyone could tell me how to do this, so I can figure out the rest I want to do. Please help me out! Thanks, Hans  View this message in context: http://www.nabble.com/Afewbeginnerproblemstf3050986.html#a8481115 Sent from the clisplist mailing list archive at Nabble.com. 
From: Klaus Ebbe Grue <grue@di...>  20070122 09:13:21

;; Hi, ;; Im a LISP beginner and I would like some help. ;; I have 2 problems that might be easy for an advanced programmer: ; I wonder whether or not clisplist@... is the right ; place to ask such questions. But I had a little spare time this morning, ; so here is a partial answer to question 2 and 3 in case you want to ; write your program in a doityourselfstyle (which I think is a good ; idea until you are no longer a LISP beginner). (inpackage "COMMONLISPUSER") ;; 2. A function that returns a list containing integers between sets of ;; lower and upper boundaries. For example: function 20 26 23 28 would ;; return: (20 21 22 23 24 25 26 27 28) ; (integerinterval m n) returns the list (m m+1 m+2 ... n) provided ; that m and n are integers and m <= n. (defun integerinterval (m n) (if (< n m) nil (cons m (integerinterval (+ m 1) n)))) ; (integerinterval1 m n) also returns the list (m m+1 m+2 ... n) ; provided that m and n are integers and m <= n. But it runs faster. (defun integerinterval1 (m n) (integerinterval2 m n nil)) ; (integerinterval2 m n result) returns the list (m m+1 m+2 ... n) ; prepended to the list 'result'. (defun integerinterval2 (m n result) (if (< n m) result (integerinterval2 m ( n 1) (cons n result)))) ; The function above is 'tail recursive' in the sense that the very ; last thing it does when (< n m) is false is that it calls *itself*. ; The integerinterval function is not tail recursive: the last thing ; it does when (< n m) is false is that it calls 'cons'. Tail recursive ; functions happen to be faster than other functions on most systems. ; (question2 s) returns a list with all integers between the smallest and ; largest element of the nonempty list s of integers. As an example, ; (question2 '(20 26 23 28)) returns (20 21 22 23 24 25 26 27 28) (defun question2 (s) (integerinterval1 (apply 'min s) (apply 'max s))) ; The function above uses (apply 'min s) to apply the minimum function to ; the list s to get the smallest element of the list. If you want to do ; that 'yourself' you can use (smallestelement s) instead: (defun smallestelement (s) (if (atom (cdr s)) (car s) (min (car s) (smallestelement (cdr s))))) ; The smallestelement function above is *not* tail recursive. One can make ; it tail recursive and thereby faster using the same trick as the one I ; used for integerinterval above. ;; 3. A random generator that chooses values form a list or a stackpile ;; without repeating any values until all have been used once. ; The following is *not* a solution to your problem. Rather, I solve ; the related problem of constructing a random permutation of the ; integers from m inclusive to n exclusive. Hopefully, you can adapt ; the code to suit your needs ; (randompermutation m n) returns a random permutation of the numbers ; m,m+1,m+2,...,n1 provided that m and n are integers and m < n. (defun randompermutation (m n) (format t "randompermutation ~s ~s~%" m n) (if (= m ( n 1)) (list m) (randompermutation1 m (floor (+ m n) 2) n))) ; (randompermutation1 m d n) returns a random permutation of the numbers ; m,m+1,m+2,...,n1 provided that m, n, and d are integers and m < d < n. (defun randompermutation1 (m d n) (format t "randompermutation ~s ~s ~s~%" m d n) (randommerge ( d m) (randompermutation m d) ( n d) (randompermutation d n))) ; (randommerge l1 s1 l2 s2) returns a random merge of the lists s1 and s2 ; provided that l1 is the length of s1 and l2 is the length of s2. When ; merging a short and a long list it picks with largest probability from ; the long list. To get all permutations with even probability it is ; important to pick with probability l1/(l1+l2) from the list of length l1. (defun randommerge (l1 s1 l2 s2) (format t "randommerge ~s ~s~%" l1 l2) (if (= l1 0) s2 (if (= l2 0) s1 (if (< (random (+ l1 l2)) l1) (cons (car s1) (randommerge ( l1 1) (cdr s1) l2 s2)) (cons (car s2) (randommerge ( l2 1) (cdr s2) l1 s1)))))) ; Cheers, ; Klaus 
From: Klaus Ebbe Grue <grue@di...>  20070123 14:50:57

Hi clisplist@..., If I type (map 'list 'charcode (convertstringfrombytes #(65 92 27 40 74 92 168) (makeencoding :charset "ISO2022JP" :lineterminator :unix :inputerroraction #\Null :outputerroraction #\Null))) then I get (65 92 165 0) The input #(65 92 27 40 74 92 168) consists of an ascii A (65), an ascii backslash (92), a shift to Japanese sequence (27 40 74), a yen sign (92) and a katakana glyph (168). The output (65 92 165 0) consists of an ascii A (65), an ascii backslash (92) a yen sign (165) and an invalid character (0). So the shift to Japanese sequence (27 40 74) seems to be recognized, but katakana (code 161223) does not seem to be recognized. Any suggestions? Cheers, Klaus  [grue@... grue]$ clisp version GNU CLISP 2.41 (20061013) (built 3370084031) (memory 3370084648) Software: GNU C 3.2 20020903 (Red Hat Linux 8.0 3.27) gcc g O2 W Wswitch Wcomment Wpointerarith Wimplicit Wreturntype Wmissingdeclarations Wnosigncompare O2 fexpensiveoptimizations falignfunctions=4 DUNICODE DDYNAMIC_FFI I. x none libcharset.a libavcall.a libcallback.a /usr/local/lib/libreadline.so Wl,rpath Wl,/usr/local/lib lncurses ldl L/usr/local/lib lsigsegv lc L/usr/X11R6/lib SAFETY=0 HEAPCODES LINUX_NOEXEC_HEAPCODES GENERATIONAL_GC SPVW_BLOCKS SPVW_MIXED TRIVIALMAP_MEMORY libsigsegv 2.4 libreadline 5.1 Features: (READLINE REGEXP SYSCALLS I18N LOOP COMPILER CLOS MOP CLISP ANSICL COMMONLISP LISP=CL INTERPRETER SOCKETS GENERICSTREAMS LOGICALPATHNAMES SCREEN FFI GETTEXT UNICODE BASECHAR=CHARACTER PC386 UNIX) C Modules: (clisp i18n syscalls regexp readline) Installation directory: /usr/local/lib/clisp/ User language: ENGLISH Machine: I686 (I686) thor.yoa.dk [127.0.0.1] 
From: Pascal Bourguignon <pjb@in...>  20070122 13:10:19

Hans3 writes: > Im a LISP beginner and I would like some help. > I have 2 problems that might be easy for an advanced programmer: Since this is not specific to clisp, but to Common Lisp, a better forum would be news:comp.lang.lisp =20 > 1. A function which will interpolate the values of 2 lists in a number = of > steps, so '(1 1 1 1 1) and '(0.5 1 1.5 2 3) would become: > ( 1.000 1.000 1.000 1.000 1.000 > 0.875 1.000 1.125 1.250 1.500 > 0.750 1.000 1.250 1.500 2.000 > 0.625 1.000 1.375 1.750 2.500 > 0.500 1.000 1.500 2.000 3.000 ) >=20 > How do I make this? Good question. How do YOU do this? =20 You've got three parameters, a from list, a to list, and a number of steps. So you should write a function: (defun interpolate (fromlist tolist numberofsteps) ...) ; fill in the ellipsis. What did you do to get the above example result?=20 (or, if given by your teacher, how would YOU do it with:=20 (interpolate '(0 0 0 0) '(1 2 3 4) 6) ?) One hint: it would be easier/more natural to generate interpolations "line by line": (interpolate '(0 0) '(3 6) 4) > ((0 0) (1 2) (2 4) (3 6)) If you want the result under the form (0 0 1 2 2 4 3 6), you can always concatenate the resulting sublists in a final step. What we have here is a division of the problem in two easier parts. It's easy ton concatenate lists, and it's easy (or at least easier than the original problem) to generate the interpolations "line by line"). > 2. A function that returns a list containing integers between sets of l= ower > and upper boundaries. For example: function 20 26 23 28 would return: > (20 21 22 23 24 25 26 27 28) > Any even number should be possible. Basically, the answer is the same;. How would YOU do it? How can you divide the problem in simplier subproblems? > 3. A random generator that chooses values form a list or a stackpile wi= thout > repeating any values until all have been used once. Idem. Do you really need to write a random generator (it's hard to do in computers). You could write a pseudorandom generator, but is it what's asked? (There is already a pseudo random generator function in Common Lisp). Perhaps what's asked is only to return the values from the stackpile in a random order? What we have here, is that you'd better know your programming language (and libraries), to be able to use existing operators to your purposes. (And also, becareful with specifications, they are often not precise enough and misleading). =20 > 4. A random generator that chooses values form a list or a stackpile wi= th a > specific weight. Example: (weight '(1 2 3) '(4 2 1)) means that 1 has a > weight of 4, 2 has a weight of 2 and 3 has a weight of 1, so 1 will be = twice > as much in a list that 2 and so on. Idem. =20 Hint: if you have a (pseudo) random generator giving integers between 0 and N1 inclusive in equiprobability, how do you map these integers to a set of N elements to keep the equiprobability? And would you map these N integers to another set of elements to get different probabilities? > I would grately appreciate if anyone could tell me how to do this, so I= can > figure out the rest I want to do. Please help me out! >=20 > Thanks, Hans =20 __Pascal Bourguignon__ http://www.informatimago.com/ READ THIS BEFORE OPENING PACKAGE: According to certain suggested versions of the Grand Unified Theory, the primary particles constituting this product may decay to nothingness within the next four hundred million years. 
From: Hans3 <tomkorver@gm...>  20070126 22:11:33

Thanks for the advice Klaus & Pascal! Although Pascal's advice is clear, I'm aware of the steps I need to follow to make these functions, I know this. What I don't know is the code... (because I don't have much experience yet) For now I have another question: How can I define a function with unlimited arguments? Example: (defun test (a &optional b c d e f g h i j k etc.... ) I would like it so that it doesnt matter how many arguments are there, so that it can be processed with a loop function until all arguments are used. Also it must be possible that in the function I can say: setf list (list *all arguments*) What command then do I need for *all arguments* ?  View this message in context: http://www.nabble.com/Afewbeginnerproblemstf3050986.html#a8659740 Sent from the clisplist mailing list archive at Nabble.com. 
From: Klaus Ebbe Grue <grue@di...>  20070127 10:07:39

> How can I define a function with unlimited arguments? > (defun test (a &optional b c d e f g h i j k etc.... ) I think you should *not* ask clisplist@... I will send an answer directly to tomkorver@... Klaus 
From: Pascal Bourguignon <pjb@in...>  20070127 12:48:25

Hans3 writes: > Thanks for the advice Klaus & Pascal! > Although Pascal's advice is clear, I'm aware of the steps I need to fol= low > to make these functions, I know this. > What I don't know is the code... (because I don't have much experience = yet) Well, the question is what does it mean to interpolate? Assume we're considering only one couple of points=20 (interpolate '(4) '(8) 3) we have the points of coordinates (0,4) and (1,8) and we want to find one (=3D32, since we count these two points) point on the line that pass thru these two points. To do that, you need to compute the equation of the line from the two points, and then you need to divide the horizontal distance between the two points by the number of interpolated points plus one, and then, you can compute the y coordinate. In this example, the equation of the line passing thru (0,4) and (1,8) is: y=3D4+4x (since 4=3D4+4*0 and 8=3D4=3D4*1) and since we need only one point in the middle, with x =3D (10)/2 =3D 0.= 5 we find y =3D 4+4*0.5 =3D 6 therefore the result is: '((4) (6) (8)) So, what you need to do, is to write a function that finds the parameters a and b of the line y=3Dax+b, that passes between two points of coordinates (0,y0) and (1,y1). Then you must compute the list of intermediate y's for the serie of n x's going from 0 to 1.=20 Once you can do it for one couple of points, ou can do it for any number of couples of points given in two lists. =20 __Pascal Bourguignon__ http://www.informatimago.com/ READ THIS BEFORE OPENING PACKAGE: According to certain suggested versions of the Grand Unified Theory, the primary particles constituting this product may decay to nothingness within the next four hundred million years. 
From: Klaus Ebbe Grue <grue@di...>  20070216 09:11:29

Hi clistlist, Can anyone give me a pointer to a newclx development site, a newclx faq or something? Reason: I did > (displayresourceidbase (closedisplay (opendisplay "127.0.0.1"))) and got > Internal error: statement in file "clx.f", line 1838 has been > reached!! Please send the authors of the program a description how > you produced this error! By the way, if a newclx expert reads this email: How does one test whether or not a given display is open or closed? I am trying to program a function (safeclosedisplay d) which closes d if d is an open display and does nothing if d is no display or a closed display. Cheers, Klaus 
From: Devon Sean McCullough <LispHacker@Jovi.Net>  20070127 18:01:45

Date: Sat, 27 Jan 2007 11:07:22 +0100 (CET) From: Klaus Ebbe Grue <grue@...> > How can I define a function with unlimited arguments? > (defun test (a &optional b c d e f g h i j k etc.... ) I think you should *not* ask clisplist@... I will send an answer directly to tomkorver@... Google [Hyperspec arguments] gets http://www.lisp.org/HyperSpec/Body/glo_a.html argument n. 1. (of a function) an object which is offered as data to the function when it is called. 2. (of a format control) a format argument. which is not helpful, mere links to equally terse glossary definitions, i.e., function, object, format control, format argument. A nice loweffort cure would be to crossreference the glossary, e.g., click the "argument" definition for a page of links to 3.4.1 Ordinary Lambda Lists and so on. Surely someone did this already? Peace Devon /~\ \ / Health Care X not warfare / \ Dubya won the digital vote Kerry won the popular vote 
From: Sam Steingold <sds@gn...>  20070218 01:56:56

> * Klaus Ebbe Grue <tehr@...> [20070216 10:11:22 +0100]: > > Can anyone give me a pointer to a newclx development site, a newclx > faq or something? sources is your doc (other than the general CLX documentation) > Reason: I did > >> (displayresourceidbase (closedisplay (opendisplay "127.0.0.1"))) > > and got > >> Internal error: statement in file "clx.f", line 1838 has been >> reached!! Please send the authors of the program a description how >> you produced this error! XLIB:DISPLAYRESOURCEIDBASE is not implemented, see the sources. http://www.cygwin.com/acronyms/#PTC > By the way, if a newclx expert reads this email: How does one test > whether or not a given display is open or closed? I am trying to > program a function (safeclosedisplay d) which closes d if d is an > open display and does nothing if d is no display or a closed display. XLIB:CLOSEDDISPLAYP  Sam Steingold (http://sds.podval.org/) on Fedora Core release 6 (Zod) http://jihadwatch.org http://truepeace.org http://palestinefacts.org http://honestreporting.com http://memri.org http://dhimmi.com Don't use force  get a bigger hammer. 
From: Klaus Ebbe Grue <grue@di...>  20070218 10:38:40

Dear Sam, >> Can anyone give me a pointer to a newclx development site, a newclx >> faq or something? > > sources is your doc (other than the general CLX documentation) Thanks  (pointer to a newclx development site) = nil was what I needed to get on. modules/clx/newclx/README answers all my questions. >> How does one test whether or not a given display is open or closed? > > XLIB:CLOSEDDISPLAYP Thanks  Klaus 