Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #52949
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | :Re: macro flow from inside to outside |
| Date | 2016-11-29 09:40 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <o1jif0$laq$1@gioia.aioe.org> (permalink) |
Peter Seibel wrote: > that didn't just throw away those valuse. Here' a version that uses > lexical variables, as requested. However it suffers from only allowing > a finite number of named bags. There may be some clever way to work > around that without walking the code. Or you could just live with it, > the same way we live with other limits such as the number of arguments > we can pass to a function. > > (defmacro bag (&body body) > (let ((bag (gensym)) > (namedbags (loop repeat 10 collect (gensym)))) > `(let ((,bag ()) > ,@(loop for bag in namedbags collect `(,bag ()))) > (flet ((find-bag (name) > (cond > (name > (loop for bag in ',namedbags > for bagname = (get bag 'bag-name) > when (eql name bagname) return bag > when (not bagname) do > (setf (get bag 'bag-name) name) and > return bag > finally (error "Out of bags"))) > (t ',bag)))) > (macrolet ((containing (item &optional name) > `(push ,item ,(find-bag name))) > (the-bag (name) > (find-bag name))) > ,@body) > ,bag)))) > > This lets you write stuff like: > > CL-USER> (bag > (dotimes (i 10) > (if (evenp i) > (containing i evens) > (containing i odds))) > (containing (the-bag evens)) > (containing (the-bag odds))) > ((9 7 5 3 1) (8 6 4 2 0)) Ruby: (0..9).partition &:odd? ===> [[1, 3, 5, 7, 9], [0, 2, 4, 6, 8]] 10.times.partition &:odd? ===> [[1, 3, 5, 7, 9], [0, 2, 4, 6, 8]] How would this be coded in Forth? Is it even possible? It seems that ANS Forth isn't used for real programming; it's just used for doing a little arithmetic. -- General Mills ... aired a television commercial for ... Cheerios ... promoting Aryan hybridization with blacks (depicting, as usual, a white woman and a black man). ... The ad agency responsible for the campaign was ... [Jewish] Saatchi & Saatchi.... www.counter-currents.com/2013/08/behind-anti-white-advertising
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
:Re: macro flow from inside to outside "Robert L." <No_spamming@noWhere_7073.org> - 2016-11-29 09:40 +0000
csiph-web