• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

DocKimbel
10-Apr-2013
[6948x2]
Endo, you could even make it a webservice that could be used with 
a simple WGET call from a command-line. ;-)
Also, when asking for the file to be downloaded, you should rename 
the file to something more human-friendly or ask the name from the 
user. You can use Content-Disposition HTTP field for doing that easily. 
Here's an example from one of CureCode's RSP:

        response/buffer: get-modes file 'full-path	

        response/set-header 'Content-Disposition  rejoin [{filename="} name 
        {"}]
Gregg
10-Apr-2013
[6950x3]
On the header, having it be Red may lead to the most false positives. 
If it's at the top of a file, it would normally be capitalized.
As long as it must be followed by a left bracket, you should be OK 
though.
I do agree that it avoids being confused as an acronym.
Kaj
10-Apr-2013
[6953]
It was my understanding that string/rs-head returns a UTF-8 cache 
of a string. How can I get this value?


I'm trying to get UTF-8 back that I fed in. The problem I'm having 
is the following:

write %syllable.org.html read "http://syllable.org"

This writes out just one character instead of the expected file.
Gregg
10-Apr-2013
[6954]
Doc, on stress testing, I was just trying to do eyeball speed testing 
of some mezz code.
Kaj
10-Apr-2013
[6955]
I agree that the allocator is important to fix
Gregg
11-Apr-2013
[6956x6]
On the stress testing, and keeping in mind that I fully expect Red 
to be slow at many things at this stage, It is really wonderful to 
see that it's not. Yes, these are still small tests, but Red still 
impresses me with what works and works so well.
And because there are holes, it makes me think about different ways 
to solve things, which is fun.
My small test was for a FILTER function:

filter: function [
	"Returns all values in a series that match a test."
	series [series!]

 test [function!] "Test (predicate) to perform on each value; must 
 take one arg" ; TBD: any-function!
	/out "Reverse the test, filtering out matching results"
][
    result: copy []
    ; The lambda here is like QUOTE, but it evaluates.
    op: either out [:not] [func [val] [:val]]
	foreach value series [
		if op test :value [append/only result :value]
	]
	result
]
Given the block size limit, I used a block with 60K elements in it:

b: append/dup copy [] [1 b #c "d"] 15000
Then tested with simple type testing funcs. e.g. 

filter b :integer?
filter/out b :integer?
etc.
I have to loop >5 times before I see *any* delay in the console prompt 
returning. At 10 times, it seems to take about a second.
Oldes
11-Apr-2013
[6962]
If you check http://www.red-lang.org/p/roadmap.htmlyou can see that 
GC is made just from 10%. You are allocating large memory blocks, 
but do not free them posibly.
Gregg
11-Apr-2013
[6963x2]
Yes, they never get freed. I "freshen" my console frequently. :-)
It doesn't seem to slow down as I continue testing. Just eats memory.
DocKimbel
11-Apr-2013
[6965]
I will have a look today at the reported Curecode issues, then I'll 
get back to Red coding, probably working first on the exception support 
for Red/System (in order to be able to implement EXIT/RETURN support 
for the interpreter).
Endo
11-Apr-2013
[6966]
Thank's for the feedbacks, making a webservice-red-compiler is a 
nice idea, but I made it for lazy people like me to be able to compile 
Red scripts easily. 

Doc: red-lang.org is on a Cheyenne server or a normal hosting service?
DocKimbel
11-Apr-2013
[6967]
Only some static resources are on Cheyenne server, the rest is hosted 
by Blogger (Google).
Endo
11-Apr-2013
[6968]
For false alarms from AV software, please report them to me so I 
can contact AV vendors to whitelist Red binaries.

, how should I report it? What to include? I can prepare zip package 
with those exe files and some info (OS versions, AV versions, etc.)
DocKimbel
11-Apr-2013
[6969x4]
Just give me the AV software name first, then the source file name 
and compilation optons (if any).
You should also upload first your binary here: https://www.virustotal.com/en/
If the AV software from virustotal doesn't give you the same error, 
you might have an older AV version.
You can post here the link to the virustotal report.
Endo
11-Apr-2013
[6973x3]
Oh sorry, when I say AV I meant AVira :) Avira Free Antivirus: http://www.avira.com/free-av
Ok I've uploaded to virustotal.com, Detection ratio:	 1 / 46, only 
avira-antivir says "TR/Crypt.XPACK.Gen" virus found.
Here is the link:

https://www.virustotal.com/en/file/2db471babe53dedbd6adf0c5c112976a6692ad000aea83dfa93890f6d1e1b43b/analysis/1365683598/
DocKimbel
11-Apr-2013
[6976]
So you just compiled tests/hello.red or did you use a custom script?
Endo
11-Apr-2013
[6977]
my script is:
Red [ ]
print "hello"
DocKimbel
11-Apr-2013
[6978]
Ok, thanks, will try to reproduce the false alarm and will contact 
AVira for reporting it.
Gregg
12-Apr-2013
[6979x2]
Since it's early days in Red, I'm toying with a lot of ideas and 
revisiting old REBOL funcs as I port them. JS has an interesting 
spin on MAP. I thought I'd see how hard it would be to do in Red.
; JS-like MAP. The order of args to the function is a bit odd, but 
is set

; up that way because we always want at least the value (if your 
func takes

; only one arg), the next most useful arg is the index, as you may 
display

; progress, and the series is there to give you complete control 
and match

; how JS does it. Now, should the series value be passed as the head 
of the
; series, or the current index, using AT?
map-js: func [

 "Evaluates a function for each value(s) in a series and returns the 
 results."
	series [series!]

 fn [function!] "Function to perform on each value; called with value, 
 index, and series args"
	/only "Insert block types as single values"
	/skip "Treat the series as fixed size records"
		size [integer!]
][
	collect [

  repeat i length? series [   ; use FORSKIP if we want to support /SKIP.
			keep/only fn series/:i :i :series ; :size ?
		]
	]
]
;res: map-js [1 2 3 a b c #d #e #f] :form
;res: map-js [1 2 3 a b c #d #e #f] func [v i] [reduce [i v]]
;res: map-js [1 2 3 a b c #d #e #f] func [v i s] [reduce [i v s]]
;res: map-js "Hello World!" func [v i s] [pick s i]
DocKimbel
12-Apr-2013
[6981x2]
Nice and short implementation! :)
An important note about such code: passing a function! as argument 
is not supported by the compiler yet, so this function could only 
work in the interpreter currently (from console or from a DO block).
Gregg
12-Apr-2013
[6983]
Good to know. Thanks. I'm trying to stay just a few steps behind 
you in what I try. :-)
DocKimbel
13-Apr-2013
[6984x14]
For Red/System fans, here's some new toy: exceptions! Here's a simple 
example for starting:
foo: func [[catch]][
	print "2"
	throw 10
	print "KO"
]

print "1"
foo
print "3"
print ["^/thrown value: " system/thrown lf]
will output:

123
thrown value: 10
A deeper nested example:

foo2: does [
	print "3"
	throw 100
	print "KO"
]

bar: func [[catch]][
	print "2"
	foo2
	print "KO"
]

print "1"
bar
print ["^/thrown value: " system/thrown lf]
will output:

123
thrown value: 100
The implementation is done and I will push it in a few minutes. It 
required about 25 additional LOC to implement all such simple exception 
system (right, 25!). ;-)
So, how does it work? When you need to interrupt the flow of code 
in a function in Red/System, currently you can just use EXIT/RETURN 
to make an early exit. But, sometimes, you need to go up through 
several nested calls, that's where the new THROW function comes handy. 
It will interrupt the execution and go up the call tree to find the 
first function that has the CATCH attribut set. It will then just 
resume execution after the last function call (from which the exception 
has been generated).


If no CATCH attribut is found, it will go up to global code and resume 
from there.
THROW requires an integer! value. Such value represent the exception 
ID and is user-defined. After the resume from a caught exception, 
you can use SYSTEM/THROWN to read the passed exception ID and act 
accordingly (usually using a SWITCH dispatcher).
Important thing to note: system/thrown needs to be manually reset, 
as the last thrown value will stay there if no exception occured. 
Such reset could be done before each call to a function that could 
generate an exception or after processing the thrown value.
I could have added a much more sophisticated system with a true CATCH 
function, but this would have made the implementation way more complex 
and would have taken a lot more time. As I need it only for Red's 
interpreter, I think this way should be enough and will be usable 
by other Red/System programmers to enhance their own code.
Thinking about it, it might be possible to allow an extended catch 
attribut with a integer value to specify the barrier value for catching 
exceptions (and avoid manual re-throwning), something like:

foo: func [[catch 100]][...]


would catch all thrown exceptions with a value <= 100 and let others 
pass up to caller.
What do you think about all this?
BTW, this exception system relies on stack frames unwinding, so it 
won't work for callbacks (CATCH attribut won't be accepted in callback 
functions anyway).
I've considered using a continuation approach for constant-time exception 
throwing (would also work from callbacks), but I didn't find a simple 
enough syntax for defining/using it without having to rely on CPS 
(Continuation-Passing Style) for every functions...

See http://en.wikipedia.org/wiki/Continuation-passing_style