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

World: r3wp

[Core] Discuss core issues

Janko
21-Jan-2010
[15560]
maybe I will try to hack it in R2 some day.. but it probably won't 
be very effective
BrianH
21-Jan-2010
[15561]
Try using APPLY in a generated wrapper function.
Janko
21-Jan-2010
[15562]
I will thanks
BrianH
21-Jan-2010
[15563x2]
It will be a little tricky if you want to support get-word and lit-word 
parameters. It might be at the same scale as APPLY in R2. See the 
source of APPLY for details.
In any case it would be a *lot* slower than making wrapper functions.
Janko
21-Jan-2010
[15565]
aha, then it's maybe not that usefull.. I have wrapper function right 
now for this case... basically I have a closure money-format-maker
BrianH
21-Jan-2010
[15566x2]
Take a look at the new functions in 2.7.7, particularly APPLY and 
CLOSURE.
I'm still hoping to make an IT function in R3 though :)
Janko
21-Jan-2010
[15568]
I will :) .. what is IT ? like the last thing on stack maybe?
BrianH
21-Jan-2010
[15569x2]
REBOL doesn't use a stack machine. IT was a proposal for a function 
to return the result of the conditional expression of the nearest 
enclosing conditional function, basically IF or UNLESS. If we can 
add CASE support too that would be amazing, but it's unlikely without 
IF being native. As it is a mezzanine IF function would need debug 
privileges.
a mezzanine IF function -> a mezzanine IT function
Davide
21-Jan-2010
[15571]
What about a "pipe" operator (as in F#), such that you can write 
something like:
read/lines %files | remove-each x [10 > length? x] | sort 

Would be simplier to read than:
sort remove-each x read %file [10> length? x]


Basically the pipe gives the parameter to the following function 
that is of the same type of the function that precede it.
BTW I think that this could be done with a dialect
BrianH
21-Jan-2010
[15572x2]
REMOVE-EACH has 3 parameters.
To know which parameter to pass along you'd need a dialect with a 
list of supported functions in its code.
Davide
21-Jan-2010
[15574x2]
yes, the second parameter is given by the pipe
but you can see the type of the parameter
BrianH
21-Jan-2010
[15576]
And how would the pipe know to send to the second parameter, when 
the first and third also allow block parameters? REMOVE-EACH is just 
another function - the meaning of its parameters is specific to that 
function.
Davide
21-Jan-2010
[15577]
isn't the first parameter of remove-each a word ?
BrianH
21-Jan-2010
[15578x2]
There's a lot of tricks that you can do with compiled languages with 
fixed function definitions that you can't do as easily in REBOL without 
whole program analysis.
>> spec-of :remove-each
== [

    {Removes values for each block that returns true. Returns remove 
    count. (Modifies)}

    'word [word! block!] "Word or block of words to set each time (local)"
    data [series!] "The series to traverse"
    body [block!] "Block to evaluate (return TRUE to remove)"
]
Davide
21-Jan-2010
[15580]
ops, wrong example ;-)
BrianH
21-Jan-2010
[15581]
It just happens that that function value is assigned to that word. 
With the next call of the piped code it might be a different function.
Janko
21-Jan-2010
[15582x2]
hehe, this is exactly where curry would be needed :))

read/lines %files | curry remove-each [ x _ [10 > length? x] ] | 
sort
for functions that take just one example you can make it yourself 
pretty simpy.. I made it last week for processing tome fixed width 
data file ..
BrianH
21-Jan-2010
[15584x2]
People say "do it in a dialect" like those come for free. There's 
dialect processing overhead, issues of when the arguments are processed, 
decisions about whether there are keywords or not. To get an idea 
about the real overhead of doing it in a dialect, look at the source 
of APPLY or MAP-EACH in R2. Both are compiled dialects.
If there's any way to make your code execute in one of the native 
dialects, do it, it's worth it.
Janko
21-Jan-2010
[15586]
data: parse-fixed-width-lines read/lines %PO.txt [
	vat-incl: 4 [ trim empty? not ]
	vat-num: 9 trim
	...
]

this func is used to execute [ trim empty? not ] with a value.. which 
is similar to pipe or stack lang with only 1 level deep stack :)) 

stream-through: func [ fs d /local x acc ] [ accumulate x acc copy 
[] fs [ do compose [ (x) d ] ] ]
Gregg
23-Jan-2010
[15587]
Janko, Ladislav did the most extensive CURRY I know of, though Joel 
Neely also did one, and a number of us have rolled simple versions 
here and there. 

http://www.fm.tul.cz/~ladislav/rebol/curry.r
Henrik
23-Jan-2010
[15588x2]
Is there any solid way to find which chars are illegal in a specific 
file system?
Never mind. Using some tables here.
Geomol
23-Jan-2010
[15590]
Henrik, I've used info here: http://en.wikipedia.org/wiki/Filename
Do you have better info?
Henrik
23-Jan-2010
[15591x2]
http://support.grouplogic.com/?p=1607

I used this one.
but I see yours is better
Terry
23-Jan-2010
[15593x2]
Any gotchas when posting xml via read/cutom [post "<my xml>"]  ?
I'm getting a "REST method is not defined" response.
Maxim
23-Jan-2010
[15595]
that will depend how the server wants the post data...
Terry
23-Jan-2010
[15596]
maybe some kind of REST header needs to be sent as well?
Maxim
23-Jan-2010
[15597x6]
not an expert on REST interfaces... though I am using one with a 
server right now...
are you sure your URL is built accoring to the server's specs?
also might want to make sure the content-type is set to: "application/xml"
(in the header)
IIRC you also need to name your post data...

complete example, something like:

header: [Content-Type: "application/xml"]
name: "get-info"

read/custom reduce ['post rejoin [ "value=" your-xml-data "&"] 'header 
header]
oops 


read/custom reduce ['post rejoin [ name "=" your-xml-data "&"] 'header 
header]
Terry
24-Jan-2010
[15603]
name "=" your-xml-data ??
Maxim
24-Jan-2010
[15604x2]
like I said it depends on the server but most servers expect a form-like 
post data.
where name is the name of the variable which stores the xml and your-xml-data 
is, obviously, your xml file content.


you might also need to url-encode the xml-data so it gets read properly 
at the other end.
Terry
24-Jan-2010
[15606]
of xml?
Maxim
24-Jan-2010
[15607x3]
eh not sure what that refers to, but I guess you refer to "which 
stores the xml" ?
name is the argument name, like you would specify in a form.
(or a url, if it where a get)