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

World: r3wp

[!REBOL3-OLD1]

BrianH
7-Jan-2009
[9277]
Here's the current source for LOAD:

load: func [
	{Loads a file, URL, or string.}
	source [file! url! string! any-block! binary!]

 /header  {Includes REBOL header object if present. Preempts /all.}

;	/next    {Load the next value only. Return block with value and 
new position.}

;	/library {Force file to be a dynamic library. (Command version)}
;	/markup  {Convert HTML and XML to a block of tags and strings.}
	/all     {Load all values. Does not evaluate REBOL header.}
	/unbound {Do not bind the block.}
	/local data tmp
][
	; Note: Avoid use of ALL func, because of /all option
	if any-block? :source [return :source]

	data: case [
		string? source [to-binary source]
		binary? source [source]
		; Check for special media load cases: (temporary code)
		find [%.jpg %.jpeg %.jpe] suffix? source [
			return load-jpeg read/binary source
		]

  url? source [read source] ; can this possibly return not binary! 
  ?
		file? source [read source] ; binary! or block of file!
	]

 ; At this point, data is binary!, a block of file!, or something 
 weird.

	if binary? :data [
		unless find [0 8] tmp: utf? data [
			cause-error 'script 'no-decode ajoin ['UTF tmp]
		]

		; Only load script data:
		if any [header not all] [ ; Note: refinement /all
			if tmp: script? data [data: tmp]
		]
	]

	unless block? :data [data: to block! :data] ; reduce overhead

 ; data is a block! here, unless something really weird is going on
	tmp: none
	
	; Is there a REBOL script header:
	if any [header not all] [ ; /header preempts /all
		tmp: unless any [

   ;not any [file? source url? source] ; removed: hdr in string is same
			unset? first data ; because <> doesn't work with unset!
			'rebol <> first data
			not block? second data
		][ ; Process header:
			attempt [construct/with second data system/standard/script]
		]
		; tmp is header object or none here
		case [
			tmp [
				remove data
				either header [change data tmp][remove data]
				tmp: tmp/type = 'module ; tmp true if module
			]
			header [cause-error 'syntax 'no-header data]
		]
	]
	; tmp is true if module, false or none if not

 ; data is a block!, with possible header object in first position

	; Bind to current global context if not a module:
	unless any [
		unbound
		tmp ; not a module
	][
		bind/new data system/contexts/current
	]

 ; data is a block! here, unless something really weird is going on

	; If appropriate and possible, return singular data value:
	unless any [ ; avoid use of ALL
		all
		header ; This fixes a design flaw in R2's LOAD
		;not block? :data ; can this ever happen?
		empty? data ; R2 compatibility
		not tail? next data
	][data: first data]
	; If /all or /header, data is a block here

	:data
]
Maxim
7-Jan-2009
[9278]
hell, I even have a "I LOVE BUSH" day every year... I'm 1/365 republican 
!
Steeve
7-Jan-2009
[9279]
argh..... my screen exploided...
Maxim
7-Jan-2009
[9280x2]
and I'm not even American!
;-)
xavier
7-Jan-2009
[9282]
brian, is there another function that is specified for loading human 
data ?
btiffin
7-Jan-2009
[9283]
Adding foreign! doesn't really change LOAD does it?  It changes the 
native  make  phase  no?
BrianH
7-Jan-2009
[9284]
We don't want foreign! by default though (or ever, but that is another 
matter), and you can't provide options to TO. We would have to support 
foreign!, or better yet fallback, incrementally with TRANSCODE.
Chris
7-Jan-2009
[9285]
Quick 'n' dirty 'load-junk (cvts: for R2; junk! is string!; blocks 
mess things up): http://www.ross-gill.com/r/load-junk.r
BrianH
7-Jan-2009
[9286]
See, that is what we need! A separate function.
Chris
7-Jan-2009
[9287x3]
Ignores comments!
Agreed Mr. B.
comments == commas...
BrianH
7-Jan-2009
[9290x2]
Look how complex LOAD is already. That is why it is now mezzanine: 
The complexity is better handled by REBOL code.
It's still fast though :)
Graham
7-Jan-2009
[9292]
Chris, 404s for me
Steeve
7-Jan-2009
[9293]
hum... Brian, switch is not faster than case in load ?
Chris
7-Jan-2009
[9294]
Hmm, that'd be http://www.ross-gill.com/r/junk.r
BrianH
7-Jan-2009
[9295x2]
Nope, case is one of the fastest functions in REBOL, even R2.
We profile everything :)
Steeve
7-Jan-2009
[9297]
i know for R2, but in R3 switch is native, no  ?
btiffin
7-Jan-2009
[9298]
Ok, I'd gladly accept a separate function, but ship it with REBOL 
for grandma and the professors of the world.  Don't make them hunt 
it down and DO it as a special case.    But to be honest, I'd still 
prefer a foreign! datatype! and advertise REBOL as a human readable 
language.  Much power in that ad imho.
Maxim
7-Jan-2009
[9299]
but we also need an unknown!  ,   junk!  ,   or  WTF!   datatype 
   ;-)    

note the intentional use of commas  ;-)
BrianH
7-Jan-2009
[9300x2]
Switch is native in R2 as well.
At least for the last few years.
Steeve
7-Jan-2009
[9302]
not in the version i use, sigh...
btiffin
7-Jan-2009
[9303]
Maxim;  And let cunning linguists write some scripts that tally the 
amount of WTF! information in wikipedia.   ;)
BrianH
7-Jan-2009
[9304]
What platform are you on? If Windows or Linux, use 2.7.6.
Chris
7-Jan-2009
[9305]
wtf! and associated query: wtf?
BrianH
7-Jan-2009
[9306]
If you are doing one comparison, IF, UNLESS or EITHER is fastest. 
For 2 to 6ish comparisons, CASE is faster. Anything above that use 
SWITCH. Profile your code patterns to see which is best in your case.
Maxim
7-Jan-2009
[9307]
I can already see it...

>> to-wtf
Steeve
7-Jan-2009
[9308]
currently, i tested with the first alpha, switch is faster than case
Maxim
7-Jan-2009
[9309]
make WTF! none
Steeve
7-Jan-2009
[9310]
BRIAN !!!!!
btiffin
7-Jan-2009
[9311]
I can see Brian's and Gabriele's point.   Clear, concise REBOL is 
power.  But so is letting non-techies use the console.  Power in 
numbers.  And it's sooo close already.
BrianH
7-Jan-2009
[9312x2]
Steeve, do you mean:
>> to-wtf none
== "BRIAN !!!!!"
:)
Maxim
7-Jan-2009
[9314]
hahahha
xavier
7-Jan-2009
[9315]
lolllll
Steeve
7-Jan-2009
[9316]
>>a: 1
>> t loop 1000000 [case [block? a [] integer? a []]] tt
0:00:00.534

>> t loop 1000000 [switch type?/word a  [block! [] integer! []]] 
tt
0:00:00.433
Chris
7-Jan-2009
[9317]
BT: It should at least be a separate function, but I suggest separate 
from the language too.  a) it's too much baggage, and b) the scope 
for recognising string patterns could better be handled in a more 
open way.
BrianH
7-Jan-2009
[9318]
I did say that errors should complain loudly, but I didn't mean complain 
to me personally :)
Steeve
7-Jan-2009
[9319]
so what did you profile Brian ?
btiffin
7-Jan-2009
[9320]
Too much baggage for the pros, yes.  Just right for a Professor of 
Geography or home user, imho.   Don't fear those that don't normally 
program, help them.  No?
Chris
7-Jan-2009
[9321]
Too much baggage for the language.  Perhaps it could be incorporated 
into a beginner's binary?  I understand the need, even for pros too...
BrianH
7-Jan-2009
[9322]
I look forward to R3 modules - then we won't have to be as picky 
about what gets included because it won't all get loaded by default.
btiffin
7-Jan-2009
[9323]
I still don't see how a lexical foreign! would be that expensive. 
 Am I just not getting it?   Again, you cant   ADD email! url!  but 
they are valid types.  Make foreign! a valid type and then REBOL 
loads anything and series! operations can operate freely.
BrianH
7-Jan-2009
[9324]
Adding a lexical foreign! means you add the overhead of checking 
for valid syntax to *all* REBOL code, not just LOAD. It removes your 
ability to trust that what comes out of LOAD is valid. That is a 
huge overhead to all REBOL code, and would be the source of most 
REBOL bugs in the future. It is a horrible thing to do to the community.
btiffin
7-Jan-2009
[9325x2]
Well, what do you mean by valid?  foreign! would be valid, no?
It becomes a new datatype! with the semantics of junk.