here's another one:
I'm popping elements of a list into table cells, but I need a better way of progressing through the list. I know there is one but I can't remember what it is. I want to use each popped element twice, but once I pop the element it's gone!
or not. any ideas?
popping thngs
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Perhaps you can work through a list using map, and pop while you go:
which uses each element twice and then removes them.
Do you have to pop them at all?
It's a bit weird, destroying a list while you're mapping it, but seems to work OK... :)
Code: Select all
(set 'l '("a1" "b2" "c3" "d4"))
(map (fn (e) (println e) (println (reverse e)) (pop l)) l)
(println l)
Do you have to pop them at all?
It's a bit weird, destroying a list while you're mapping it, but seems to work OK... :)
I probably don't have to pop anything, but the better solution is evading me.
Shield your eyes, here is a bit of code. stu is the list.
If you stare at that too long, insanity may result. You have been warned.
:-)
Shield your eyes, here is a bit of code. stu is the list.
Code: Select all
(dotimes (x 5)(if (empty? stu)(push "Nobody" stu))(print (append "<td>"(string(inc w 1)) ". [["(set 'blap (pop stu))"]][image:" blap".gif ]</td>")))
:-)
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
I think what you've got is fine. Perhaps slightly cleaner:
It might be slightly easier if you 'fixed' the list before outputting it, so that your subsequent list manipulations are simpler:
Code: Select all
(for (x 1 5)
(println
(if (empty? stu)
(format {<td>%d. [[Nobody]][image:Nobody.gif]</td>} x)
(format {<td>%d. [[%s]][image:%s.gif]</td>} x (first stu) (pop stu)))))
Code: Select all
(set 'stu (append '("a" "b") (dup "Nobody" 3 true)))
(map (fn (n) (println (format {<td>%d. [[%s]][image:%s.gif]</td>} (+ $idx 1) n n))) stu)
Ok, I have my famous web app working, more or less, but I've still got questions to assail you guys with. a generated web page displays newlisp errors that are expected but harmless. I tried to use some error handling functions to keep it from displaying, but with no luck. the page tries to display parts of a list that doesn't exist yet; click the submit button and the error goes away. What can I do about that?
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
... show us the code :)
Or rather, distill the problem to the smallest possible, then show us!
On the face of it it sounds like you should test lists before displaying them...
which I use for my pages...
Or rather, distill the problem to the smallest possible, then show us!
On the face of it it sounds like you should test lists before displaying them...
Code: Select all
(if-not (null? expression)
(set 'output {stuff to show})
(set 'output {}))
I should probably keep all of my blathering about this to one topic--I just noticed I've started four of them so far for just simple questions. Sorry about that. In an effort to consolidate, I'll revisit a question from one of those other topics here: Why won't my modified newlisp wiki work in Internet Explorer in Windows? It works in Firefox in Windows. I solved the problem once, and it worked, but now I've gone and forgotten what I did. It was something simple. Any ideas?