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

World: r3wp

[Core] Discuss core issues

kcollins
8-May-2009
[13692]
You might want to revise the Curecode ticket to be more explicit. 
As it is now I believe it is vulnerable to misinterpretation.
Maxim
8-May-2009
[13693]
like how to handle /tail
Anton
9-May-2009
[13694x4]
MAP is close to what you want.

data: [1 2 3 4 5 6 7 8 9 10]
map v data [either v > 5 [v][]]
;== [6 7 8 9 10]
foronly: func [cond data][map v data compose [either (cond) [v][]]]
foronly [v > 5] data
;== [6 7 8 9 10]
foronly [even? v] data
;== [2 4 6 8 10]
(A better name for FORONLY would probably be FINDALL or something 
like that.)
It's related to COLLECT and I suppose "GATHER".
Janko
12-May-2009
[13698x2]
do any of you rebol gurus see a way to do something like coroutines 
/ yield / generators with rebol - so far a lot was possible to be 
done in rebol on a library level because it can change it's own code 
and because primitives aren't really primitives, but I don't see 
how this could be done ( there is magical do/next but it would block 
until loop exits so for something like this example it won't work). 
I am not sure I know the exact definition of coroutines so I will 
give an simple fictional example.. 

...
retvieve-time: func [ node /local msg ] [ 
	send-message node "get-time"
	while [ not msg: get-waiting-message ] [ yield ]
	print [ "the time is" msg ]
]

append *processes* :retrieve-time
retrieve-time *timer-node*

forever [ foreach p *processes* [ continue p ] ]


Yield returns controll from function, and next time continue is function 
continues at that point. I know the example isn't technically correct 
(for example when function exits it should be flagged and cleared 
from *processes* etc) , but just for illustration what I am asking
I made progress with my simple actors library few weeks back  but 
I still ahvent found time to make a blogpost about it.. it works 
nicely without something like yield and probably even has few advantages, 
but I am interested if somehow this can be made on top of rebol too
BrianH
12-May-2009
[13700]
R3 will have multitasking. For R2 you need to write your own interpreter, 
or switch the semantics (actors), or multiprocess.
Robert
13-May-2009
[13701]
I will never remember the trick: How can I get an output of 12.30 
instead of 12.3?
[unknown: 5]
13-May-2009
[13702x2]
BrianH, R3 discussions should go in the Rebol3 group.
(The hypocrisy).
Geomol
13-May-2009
[13704]
Robert, do you mean using money datatype?

>> $12.3
== $12.30

or maybe something like

>> append mold 12.3 "0"
== "12.30"
Robert
13-May-2009
[13705x9]
ah, I forget about money! in R2... thx.
Next one: I need to construct a HREF="..." with some dynamic code.
compose [<a href="/rest-cart/ordet/ (to-string session/id) "> "Bezahlen" 
</a>]
Of course this doesn't work. But converting the TAG to strings and 
than combining it all didn't work too.
And why this:
>> rejoin [<a href="test"> "Test" </a>]
== <a href="test"Test</a>>
This works but is ugly:
>> rejoin [<a href="test"> "Test" </a>]
== <a href="test"Test</a>>
sorry, I mean this:
>> to-tag rejoin [{a href="test">} "Test" "</a"]
 
== <a href="test">Test</a>
Henrik
13-May-2009
[13714]
Robert, what about BUILD-TAG?
Robert
13-May-2009
[13715x2]
;) He, he... to may functions to remember. Yep I think this works 
too and looks better.
Money: And way to get rid of the $ sign? I need Û at the end.
Sunanda
13-May-2009
[13717]
second $3.4
== 3.4
Robert
13-May-2009
[13718x2]
Without REMOVE etc.
Ah, cool. Didn't know this. Always something new after so many years...
Sunanda
13-May-2009
[13720]
Just tried it with R3-alpha ..... It does  not work.
I'll report it in Curecode.
Robert
13-May-2009
[13721]
Good, at least it helped to catch a bug.
Sunanda
13-May-2009
[13722]
:-)
  to-decimal $3.4

works in R3 but not R2.....So it may be a change of behavior, not 
a bug. Look out for reponse to curecode #807
Robert
13-May-2009
[13723]
But does it give the trailing 0 in R3?
Sunanda
13-May-2009
[13724]
Does not look like it:
    >> to-decimal $3.4
    == 3.4
Sunanda
14-May-2009
[13725]
Looks like to-decimal will be the R3 way:
http://curecode.org/rebol3/ticket.rsp?id=807
amacleod
14-May-2009
[13726]
How can I track the number of times a word/phrase occurs in a string!
I tried this: 
	if find str "a phrase" [print "found phrase"]
but it seems to only find the first occurance.
Steeve
14-May-2009
[13727]
is that a joke ?
Graham
14-May-2009
[13728x4]
use parse
There are examples on Rebol.com on how to use parse to count occurences 
ot tags etc.
of course it would be nice to have something like find/all which 
returns a block of all the occurences
Steeve... this is not the humour group!
Steeve
14-May-2009
[13732]
hmm...
 i: 0 while [str: find/tail str "a phrase"][i: i + 1]
Henrik
14-May-2009
[13733]
parse str [any [thru "a phrase" (print "found phrase")]]
Steeve
14-May-2009
[13734]
but it would be more relevant to post such request in "i'm new"
amacleod
14-May-2009
[13735]
I'm using to highlight parts of strings in a face during a text search. 
so I need to find caret offsets for each and append to the face/effect/draw 
block
Graham
14-May-2009
[13736]
findall: func [ st occurrence /local result ][
	result: copy []
	while [ st: find st occurrence ][ append result st st: next st]
	result	
]

>> findall "testing" "t"
== ["testing" "ting"]
Henrik
14-May-2009
[13737]
in that case, would you want the indexes?
Maxim
14-May-2009
[13738]
graham's solution does exactly that
Henrik
14-May-2009
[13739]
something like that has also been proposed for R3.
Graham
14-May-2009
[13740]
findall: func [ st occurrence /local result ][
	result: copy []

 while [ st: find st occurrence ][ append result index? st st: next 
 st]
	result	
]

>> findall "testing" "t"
== [1 4]
Henrik
14-May-2009
[13741]
would it be too clever to return the block at the positions instead 
of the index?