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

World: r3wp

[Core] Discuss core issues

TomBon
22-Feb-2011
[979]
is there any other compression which returns a string instead a binary?
GrahamC
22-Feb-2011
[980x3]
You can just form a binary ... to get a string
Mind blank ..anyone got a routine to trim a particular character 
from the end of a string?  I want to remove trailing pipe characters
I could reverse the string and then parse it using a charset .. but 
that seems crude ( any reason why the parse direction can not be 
made an option ? )
BrianH
22-Feb-2011
[983x4]
That's one of the proposals that hasn't been implemented yet.
Why not use FIND with the charset?
All trailing pipe characters? Do you want to remove any other characters 
other than | ?
>> b: charset [not "|"]
== make bitset! [not bits #{00000000000000000000000000000008}]
>> find/reverse/tail tail "abc|||" b
== "|||"
GrahamC
22-Feb-2011
[987x2]
looks like R3 to me!
I want to remove trailing |
BrianH
22-Feb-2011
[989]
For R2 you might need to complement the charset rather than using 
not.
GrahamC
22-Feb-2011
[990]
I didn't know you could use find with a charset
BrianH
22-Feb-2011
[991x2]
>> b: complement charset "|"
== make bitset! #{
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
}
>> next find/reverse tail "abc|||" b
== "|||"
>> head clear next find/reverse tail "abc|||" b
== "abc"
FIND/reverse/tail doesn't work in R2.
GrahamC
22-Feb-2011
[993]
I'll give it a go... ta
BrianH
22-Feb-2011
[994]
So you might need to do a bit of tweaking for the R2 version, but 
it's a start.
GrahamC
22-Feb-2011
[995]
is this being backported to R2?
BrianH
22-Feb-2011
[996]
FIND/reverse/tail works in R2, but not with charsets. It's a bug.
GrahamC
22-Feb-2011
[997x2]
as I thought ... no find with charsets
oh ... ooops
BrianH
22-Feb-2011
[999]
FIND works with charsets in R2, but the /tail option doesn't. It's 
a newly discovered (just now) bug.
GrahamC
22-Feb-2011
[1000]
just now ??
BrianH
22-Feb-2011
[1001]
Yeah. By me, just now, while I was doing this experiment.
GrahamC
22-Feb-2011
[1002]
neat
BrianH
22-Feb-2011
[1003]
Thanks :)
GrahamC
22-Feb-2011
[1004x4]
find/reverse tail a b only finds the first |
>> a
== "abcd|as|dsf|||||"

>> index? find/reverse tail a b
== 16
oops ...
no sleep :(
BrianH
22-Feb-2011
[1008]
That's where the CLEAR comes in :)
GrahamC
22-Feb-2011
[1009x2]
By George I think I've got it!
BTW, I think trim/with/tail should actually do this .. but trim/with 
removes characters inside the string.
BrianH
22-Feb-2011
[1011]
Yeah, for TRIM /with implies /all.
GrahamC
22-Feb-2011
[1012]
replace/all does the same ... so perhaps trim/with should be changed
Andreas
23-Feb-2011
[1013]
>> map-each a [] [1]
** Throw Error: Return or exit not in function
** Where: map-each
** Near: return any [output make block! 0]

>> system/version
== 2.7.8.4.2
BrianH
23-Feb-2011
[1014x3]
Darn, my bad. It's the [throw] function attribute. Don't worry, there's 
a way to reorganize the code so no RETURN is necessary.
Thanks for the report. I'll fix it in R2/Forward right away.
Here's a working version:

map-each: func [

 "Evaluates a block for each value(s) in a series and returns them 
 as a block."
	[throw catch]

 'word [word! block!] "Word or block of words to set each time (local)"
	data [block!] "The series to traverse"
	body [block!] "Block to evaluate each time"
	/into "Collect into a given series, rather than a new block"

 output [any-block! any-string!] "The series to output to" ; Not image!
	/local init len x
][
	; Shortcut return for empty data
	either empty? data [any [output make block! 0]] [
		; BIND/copy word and body
		word: either block? word [
			if empty? word [throw make error! [script invalid-arg []]]

   copy/deep word  ; /deep because word is rebound before errors checked
		] [reduce [word]]
		word: use word reduce [word]
		body: bind/copy body first word
		; Build init code
		init: none
		parse word [any [word! | x: set-word! (
			unless init [init: make block! 4]
			; Add [x: at data index] to init, and remove from word
			insert insert insert tail init first x [at data] index? x
			remove x
		) :x | x: skip (

   throw make error! reduce ['script 'expect-set [word! set-word!] type? 
   first x]
		)]]
		len: length? word ; Can be zero now (for advanced code tricks)
		; Create the output series if not specified
		unless into [output: make block! divide length? data max 1 len]
		; Process the data (which is not empty at this point)

  until [ ; Note: output: insert/only output needed for list! output
			set word data  do init

   unless unset? set/any 'x do body [output: insert/only output :x]
			tail? data: skip data len
		]
		; Return the output and clean up memory references
		also either into [output] [head output] (
			set [word data body output init x] none
		)
	]
]
Henrik
7-Mar-2011
[1017]
I'm studying the RIP archive format and am wondering:


Why does LOAD allow binary "junk" at the end of a file, if it has 
a REBOL [] header, while it does not, when the header is omitted?
Oldes
7-Mar-2011
[1018]
I don't think that LOAD allow binary "junk"
Rebolek
7-Mar-2011
[1019]
afair, LOAD allows REBOL scripts to be embedded in "junk"
Oldes
7-Mar-2011
[1020x8]
No.. it doesn't... it's possible to DO a script which has some sort 
of junk, but not LOAD.
>> load {234523$%$%^& rebol [] print 1}
** Syntax Error: Invalid integer -- 234523$%$%&
** Near: (line 1) 234523$%$%& rebol [] print 1
>> do {234523$%$%^& rebol [] print 1}
** Syntax Error: Invalid integer -- 234523$%$%&
** Near: (line 1) 234523$%$%& rebol [] print 1
>> write/binary %x.r {234523$%$%^& rebol [] print 1}
>> do %x.r
** Syntax Error: Script is missing a REBOL header
** Near: do %x.r
>> write/binary %x.r {234523$%$%^& ^/rebol [] print 1}
>> do %x.r
1
you can have junk at the beggining as long as you have the header 
there (  rebol at the newline start)
rebol with following block.. this does not works:
>> write/binary %x.r {234523$%$%^& ^/rebol none print 1}
>> do %x.r
** Syntax Error: Script is missing a REBOL header
** Near: do %x.r
this works as well:
>> write/binary %x.r {[^/rebol [] print 1] 34532$%*&%$#}
>> do %x.r
1
hmm.. ok... the LOAD is possible as well:
>> load %x.r
== [print 1
]
so you are right
I guess it's how the load/next is implemented... if the header is 
inside a block, it stops there.
Henrik
10-Mar-2011
[1028]
I forget: How do you open an Explorer window from Rebol?