r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Volker
16-Nov-2005
[2782]
l: first[ ((b c) (b () d)) ]
subst: func[l old new][
 forall l[
  either any-block? l/1 [
   subst l/1 old new
  ][
   if old == l/1 [ l/1: new ]
  ]
 ]
 l
]
probe l
probe subst l 'b 'a
JaimeVargas
16-Nov-2005
[2783]
Nice. Replace on place. ;-)
Volker
16-Nov-2005
[2784x6]
Hmm, no, there are atoms and lists. So i have to dig a bit deeper. 
then cons is really a 'reduce. but lisp has no lists with multiple 
elements, thats mold-sugar. WHile we have in rebol and your cons 
can deal with that.
(AFAIK, i am longtime lisp newbie)
But isnt that what insert/only does? putting a new value in front 
of a series? To match exactly it would be into a copy of the series, 
but i guess that does not matter.
I hope i got the lisp right
cons: func[left rest][
 head insert/only copy rest left
]
subst: func[new old slist /local left rest][
 if tail? slist[return head slist]
 (cons 
  subst-in-symbol-expression new old first slist
  subst new old copy next slist
 )
]
subst-in-symbol-expression: func[new old se][
 if not any-block? se[
  if equal? se old [ return new ]
  return se
 ]
 subst new old se  
]
print "10 9 8 7 6 5 4 3 2 1 0 ??"
probe l: first[ ((b c) (b () d)) ]
probe subst 'a 'b l
(and it must be a copy, on several places)
JaimeVargas
16-Nov-2005
[2790x2]
Only one problem with you cons
cons [] [] ;== [[]] 

it should be

cons [] [] ;== []
Volker
16-Nov-2005
[2792x3]
But together with the rest it works.
:)
Is this the only problem left?
JaimeVargas
16-Nov-2005
[2795x2]
I think. Very nice and short cons.
Maybe it should be part of the mezz.
Volker
16-Nov-2005
[2797x2]
Not much rebol left:
cons: func[left rest][
 if all[ [] = left [] = rest ][ return copy [] ]
 head insert/only copy rest left
]
car: :first
null?: :tail?
cdr: func[series][ copy next series ]
subst: func[new old slist /local left rest][
 if null? slist[return make slist 0] ; same series-type please
 (cons 
  subst-in-symbol-expression new old car slist
  subst new old cdr slist
 )
]
subst-in-symbol-expression: func[new old se][
 if not any-block? se[
  if equal? se old [ return new ]
  return se
 ]
 subst new old se  
]
print "10 9 8 7 6 5 4 3 2 1 0 ??"
probe l: first[ ((b c) (b () d)) ]
probe subst 'a 'b l
JaimeVargas
16-Nov-2005
[2799]
I think this CONS could be added to the mezz.

cons: func [left rest [series!]][

    if all [series? left empty? left empty? rest] [return copy rest] 
    head insert/only copy rest left
]
Volker
16-Nov-2005
[2800x3]
Maybe a set of lisp-porting-tools? In rebol itself i use more iteration 
and insert/append. No need for cons. In lisp its recursion and list-building, 
there it is helpfull.
Your version is better, keeping the type on empty lists.
Which lisp do you use? emacs, scheme, common?
JaimeVargas
16-Nov-2005
[2803]
PLT Scheme
Volker
16-Nov-2005
[2804]
Would you teach me? :)
JaimeVargas
16-Nov-2005
[2805x3]
I rather point you the two best books I have read on this:
- How to Design Programs http://www.htdp.org/

- Essentials of Programmin Languages http://www.cs.indiana.edu/eopl/
I am started to read the 'EoPL' book this week. It has been an eye 
opener. Both books a very easy to follo the HTDP book is completely 
online.
EoPL is about how to create programming languages.
Volker
16-Nov-2005
[2808x3]
I start a bit with the online-version.
And learn EoPL in discussions here :)
That EoPL looks interesting. got contents and foreword http://www.cs.indiana.edu/eopl/front.ps
. Like it.
Maarten
17-Nov-2005
[2811]
I got it, it is a hard book. I haven't gotten the time to get through 
it with my job and kids, but what I have done was well worth it. 
EopL and the "book with the dragons" by Aho et al about complier 
design are books that change your view on programming.
Graham
17-Nov-2005
[2812]
hard book as in hard back or hard to understand ?
Maarten
17-Nov-2005
[2813]
Both (at least for me ;-)
Graham
17-Nov-2005
[2814]
ahh ... so it was a pun
JaimeVargas
17-Nov-2005
[2815]
Latest CONS it takes into account that rebol has different types 
of series!

cons: func [left rest [series!]][
	if all [
		series? :left 
		equal? type? :left type? :rest
		empty? :left empty? :rest
	] [return copy :rest]
    head insert/only copy :rest :left
]
Volker
17-Nov-2005
[2816]
http://polly.rebol.it/test/test/cons/cons.rupdated :)
Pekr
23-Nov-2005
[2817x4]
how can I get some deeper context words? :-) I just wanted to check, 
if request-date finally uses system structure month/day names, so 
I sourced it:

request-date: func ["Requests a date." /offset xy][
    result: none
    if none? base [init]
    either offset [inform/offset date-lay xy] [inform date-lay]
    result
]
then I tried to add following:

insert at second :request-date 11 [probe date-lay]
but it does not know date-lay, like the word I added this way would 
not be bound to the context of the function? But looking at source 
it seems correct :-)
IIRC I successfully used such aproach in the past :-)
DideC
23-Nov-2005
[2821x3]
About request-date, I had reworked it for the "first" View 1.3 project 
(2 years ago). It use locales and some other enhancements. Just test-it 
directly :
do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=request-date
.r
Or have a look to the req-funcs object (with anamonitor ).
Anton
24-Nov-2005
[2824x2]
Pekr, you can do it by binding your 'date-lay to the 'date-lay that 
is already in the function body.

 insert second :request-date bind [probe date-lay] pick pick second 
 :request-date 10 2

(Mmm... request-date is quite an ill-behaved function. It sets 5 
words in the global context.)
Above I have bound your whole block of code to the existing 'date-lay 
word.

It could be better (a more reliable way in other situations) to bind 
just the 'date-lay word in your new code
(ie. only the words which need binding):

 insert second :request-date compose [probe (bind 'date-lay pick pick 
 second :request-date 10 2)]
Graham
25-Nov-2005
[2826]
Should 'forskip not take a block ?  As it is, it only takes a word.
Henrik
25-Nov-2005
[2827]
same with forall. a tad annoying, me thinks
Graham
25-Nov-2005
[2828]
Rambo it ?
Geomol
26-Nov-2005
[2829]
If it took a block, how would you make a reference to where you are 
in the block?
Graham
27-Nov-2005
[2830]
if you wish to parse a literal which changes ... how would you do 
that?

parse phrase [  'literal ]

can't be done this way

parse phrase compose [ '(literal) ]
Tomc
27-Nov-2005
[2831]
have you tried  parse phrase to block! join "'" 'literal