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

World: r3wp

[Core] Discuss core issues

BrianH
4-Nov-2005
[2661]
A lot of the time I do my dialect processing with functors, functions 
that create functions. Sometimes these functors run in pre-rebol, 
some at runtime function creation time. Then the actual work is done 
by the generated functions. This gives me the advantages of dialects 
without the drawbacks. On the other hand, dialects like draw are 
examples of my principle of low overhead in proportion to the that 
of the work performed - the dialect overhead isn't that much different 
to that of a series of function calls in the do dialect.
Gregg
5-Nov-2005
[2662x2]
Adding things like this to path notation hides a lot of compuational 
complexity. Sometimes that's a very good thing, and sometimes it's 
not. And consider what should happen in the case that "my-block/[2 
3]" refers to a two-dimensional array, or a block of name value pairs; 
what should the result be? Something like that fits very well in 
a dialect where the power is leveraged, and the domain is tightly 
constrained. That's where we get power and safety combined.
http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlGGHC
Volker
5-Nov-2005
[2664]
for shortness, we can use short function-names, sl: :slice  sl string 
2 4 .
If we play with extensions, i propose an operator '..
  s/2 .. 4
Graham
5-Nov-2005
[2665x2]
I suggest we just adopt the Python syntax for slicing strings, and 
accept that this is a dialect for handling string slicing, and not 
2 or more dimensional arrays.
And other one dimensional series.
Louis
5-Nov-2005
[2667]
Is there any way to send email in such a manner as to cause a window 
to pop up on the recepient's email client requesting confimation 
that they received the email?
Graham
5-Nov-2005
[2668]
Yes, and I presume that it is one of the X- type fields.
Louis
5-Nov-2005
[2669]
Do you have a link to some how to info?
Graham
5-Nov-2005
[2670]
nope .. do a google search.
Louis
5-Nov-2005
[2671]
Thanks.
JaimeVargas
5-Nov-2005
[2672]
I think that slice is much more general than the single string domains. 
So if introuduce it needs to be with care. Beside Graham if you are 
using a lot of substrings just create your own func it will make 
your code more explicit to your problem domain.
Gordon
5-Nov-2005
[2673]
Record: [a b c d e f g h i]
foreach mold Record SeriesBlock [
   print record
]

Can someone tell me how to define a block (as in Record) and then 
use that variable in the foreach loop?
Although the array has values, nothing is printed in the loop.

When I remove the 'mold' statement, 'Record' contains just one value 
('a') not 9 (a b c d e f g h i).
DideC
5-Nov-2005
[2674]
>> foreach letter record [print letter]
a
b
c
d
e
f
g
h
i
Gordon
5-Nov-2005
[2675x2]
okay?
Where is the 'block' argument?
DideC
5-Nov-2005
[2677x2]
>> help foreach
USAGE:
    FOREACH 'word data body

DESCRIPTION:
     Evaluates a block for each value(s) in a series.
     FOREACH is a native value.

ARGUMENTS:

     word -- Word or block of words to set each time (will be local) (Type: 
     get-word word block
)
     data -- The series to traverse (Type: series)
     body -- Block to evaluate each time (Type: block)
In this example,
WORD is letter
DATA is record
Body is [print letter]
Gordon
5-Nov-2005
[2679]
I want to use two block arguments.  One for word (value that gets 
set each time) and of course the 'data' block.
DideC
5-Nov-2005
[2680x2]
Oh wait...
you can't with foreach!
Gordon
5-Nov-2005
[2682x6]
actually you can.  Working example to follow
foreach [a b c d e f g h i] Datablock [ print [a b c d e f g h i]]
This traverses the datablock and sets each of the 9 values and prints 
them as a record.
However, I want to be able to set a variable instead of hardcoding 
"[a b c d e f g h i]"
ex: Record: array 9
then
foreach record datablock [ print record]

but when I do that, record doesn't contain an array of values
DideC
5-Nov-2005
[2688x2]
Sorry I don't understand what you want to do :-\
Oups, cross post
Volker
5-Nov-2005
[2690x2]
!> w: [a b]
== [a b]
!> foreach :w [1 2 3 4][? a ? b]
A is an integer of value: 1
B is an integer of value: 2
A is an integer of value: 3
B is an integer of value: 4
me too, and wrong.
Gordon
5-Nov-2005
[2692]
okay just a minute
DideC
5-Nov-2005
[2693]
Ok, you want dynamic block of word to set, right?
Sunanda
5-Nov-2005
[2694x2]
Yiu can't have one variable -- you need a set of them, eg:
foreach [key data] ["a" 1232 "c" 7737 "z" 777] [print [key data]]
But you can fake it something like this......
data:  ["a" 1232 "c" 7737 "z" 777]
for nn 1 length? data 2 [print [pick data nn pick data nn + 1]]
Gordon
5-Nov-2005
[2696]
record-sort: func [record [block!] num [integer!]] [
    tmp: copy []
    new: copy []
    foreach [a b c d] record [append/only tmp reduce [a b c d]]
    sort-method: func [a b] [(at a num) < (at b num)]
    foreach rec sort/compare tmp :sort-method [append new rec]
    return new
]


Here is the record-sort example given in the docs.  Problem is this 
only works for records that have four items.
Volker
5-Nov-2005
[2697]
the easier way is forskip. 'foreach needs a binding-trick
DideC
5-Nov-2005
[2698]
build the code then do it :)
Gordon
5-Nov-2005
[2699x2]
Sunanda: Thanks for the example.  I'll play with your example and 
see what I can do.
Volker: Thanks.  I'll take a look at using forskip
Volker
5-Nov-2005
[2701]
why must it be in words?
Gordon
5-Nov-2005
[2702x3]
The goal is to rewrite the record-sort function so that the number 
of elements is not hard coded into the function.
I want to be able to pass the function another value which equals 
the number of elements in a record and then do something like Record: 
array {Elements}
within the function.  This would make the function more universal.
DideC
5-Nov-2005
[2705]
>> print-n: func [record words] [do compose/deep [ foreach [(words)] 
record [print [(words)]]]]

>> print-n [1 2 3 4 5 6 7 8 9] [a b c]
1 2 3
4 5 6
7 8 9
Volker
5-Nov-2005
[2706]
forskip record 4 [append/only tmp copy/part record 4]
Gordon
5-Nov-2005
[2707]
Humm.  That looks like it will work.
Sunanda
5-Nov-2005
[2708]
does sort/skip directly do what you want?
Gordon
5-Nov-2005
[2709x2]
I'm not sure.  I don't think so but I can't remember why not.
Something about reordering the records makes sort/skip not suitable.