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

World: r3wp

[Core] Discuss core issues

Graham
4-Aug-2009
[14372]
at least the hair is good
BrianH
4-Aug-2009
[14373]
It is :)
Graham
4-Aug-2009
[14374]
third :now only gives me a block
BrianH
4-Aug-2009
[14375]
You use that block as the spec block of your new function. Save a 
reference to the old, and then call it in your new function from 
your saved reference. Natives don't have body blocks.
Graham
4-Aug-2009
[14376]
too hard!
Gabriele
4-Aug-2009
[14377x2]
do you need all the refinements to work? otherwise, just make a fixed-now 
function or something like that.
if you need al refinements to work, you'll have to pass them on. 
easiest way is to grab some version of APPLY and use that.
Graham
4-Aug-2009
[14379x3]
Yes, need the refinements too
I want a drop in replacement 'now that also accesses a fixed time 
offset that is calculated at program start up.
I am using Ladislav's get-nist-correction
BrianH
4-Aug-2009
[14382]
That's tricky to do without R3 or R2/Forward - the number of comparisons 
is exponential to the number or refinements.
Gabriele
4-Aug-2009
[14383]
since you have to always add the offset, you're actually always calling 
the native without any refinements (or maybe with /precise), then 
you add the offset, and only then you "apply" the refinements (eg. 
return the year if /year was used)
Graham
4-Aug-2009
[14384]
yes. that's what I was trying.
Gabriele
4-Aug-2009
[14385]
so, i guess in this case APPLY would not really help... you wouldn't 
be able to add the offset to the result of now/year
BrianH
4-Aug-2009
[14386]
Ouch :(
Graham
4-Aug-2009
[14387x2]
I modified this script which Peter and I wrote

    nist-now: func [ 
  {corrects for time drift}
  /year       "Returns the year only."
  /month      "Returns the month only."
  /day        "Returns the day of the month only."
  /time       "Returns the time only."
  /zone       "Returns the time zone offset from GMT only."
  /date       "Returns date only."

  /weekday    "Returns day of the week as integer (Monday is day 1)."
  /yearday    "Returns day of the year (Julian)."
  /precise    "Use nanosecond precision."
  /local
    utc 
    first-jan "used to calculate the day of the year"
][
  
  utc: either precise [
    system/words/now/precise
  ][
    system/words/now
  ]
  utc: utc + nist-offset  
  return case [
    year [utc/year]
    month [utc/month]
    day [utc/day]
    time [utc/time]
    zone [utc/zone]
    date [utc/date]
    weekday [utc/weekday]
    yearday [

      either system/version > 2.6.2 [   ;; no /yearday refinement before 
      then
        utc/yearday
      ][
        first-jan: to date! join "01-01-" utc/year
        utc - first-jan + 1
      ]
    ]
    #[true] [utc]
  ]
now, this clearly won't work

now: :nist-now
BrianH
4-Aug-2009
[14389]
Save a private reference to now like this:
    now*: :now
then use now* in nist-now.
Graham
4-Aug-2009
[14390x5]
ahh... easy enough, I think that works.
thanks
getting an error with now/precise
removing the now*: :now from the private context solves that.
the info? function appears to send a http HEAD to a URL, but the 
http protocol doesn't appear to allow a user to send a HEAD.
So, how does info? do it?
Anton
5-Aug-2009
[14395]
INFO? uses QUERY, and QUERY's behaviour on a port is defined in the 
port's scheme (in this case the HTTP port scheme).

The QUERY function in the HTTP scheme just sets a flag  querying: 
true  and calls OPEN on the port, so the query behaviour is an   
internal behaviour (closed source).
Graham
5-Aug-2009
[14396]
Just wondering how it can set the querying flag to true before opening 
the port ...
Gabriele
5-Aug-2009
[14397x3]
Anton, the source to OPEN is there, so no, it's not closed source. 
:) QUERY on HTTP does a HEAD request.
Graham: if your port is already open, query just returns the information 
that is already available. if the port is not open, query does a 
HEAD instead to just get the information it needs. the same code 
as open is reused.
I don't remember if it's possible to do open/custom ... [method HEAD] 
or something like that.
Graham
5-Aug-2009
[14400x3]
I couldn't see a way to do that with the standard http protocol
I can see where it checks to see if querying is true or not to decide 
whether to use 'GET or 'HEAD
just not clear how this is invoked
Robert
5-Aug-2009
[14403]
Just wondering is there a way where I can continue with the next 
round from inside a FOREACH, REPEAT etc. loop?
Anton
5-Aug-2009
[14404x6]
Gabriele, I was half-waiting for your admonishment. :)
Graham, hang on, I think I do something like that in my batch-download 
function.
No... or was it with that experimental FTP stuff I did...
Graham,

 port: make port! [scheme: 'http host: "rebol.com" target: "index.html"]
	query port
then
	probe port/size
	porbe port/date
	probe port/locals/headers
make some decision
	open port
etc..
	close port
Robert, you can do it using
	loop 1 [
		if cond [break]  ; (Continue)
	]
eg.
	foreach word [a b c][
		loop 1 [
			if word = 'b [break] ; (Continue)
			print word
		]
	]
Outputs:
a
c
Sunanda
5-Aug-2009
[14410]
Or wait for REBOL3 and use CONTINUE :)
Robert
5-Aug-2009
[14411]
Anton, ah, tricky. Using a wrapper loop. Nice.
Graham
5-Aug-2009
[14412]
Thanks .. I shall try
Anton
6-Aug-2009
[14413x2]
Gabriele, where do we access the R2 OPEN native function source? 
I had a look in DevBase and didn't see it there.
(This is just out of curiosity; enough mezz source is available for 
Graham's question.)
Dockimbel
6-Aug-2009
[14415]
OPEN native is just a shortcut for INIT then OPEN functions in the 
scheme handler. For example :
>> help system/schemes/http/handler
Graham
7-Aug-2009
[14416x3]
I've patched my version of the http protocol http://rebol.wik.is/Protocols/Http
so that I can more easily issue a head command
so I can do this ... read/custom url [ HEAD "" ]


which is more like exists? for a url, and returns an error if it 
ain't there.
The problem with query on a port is that I can't send custom authentication 
headers that might be needed.  This way I can.

In particular I need to check for the existence of a S3 object which 
needs authentication to access.
Gabriele
7-Aug-2009
[14419]
Anton, if you have the SDK, it's prot-root.r and prot-http.r. Those 
files should also be on DevBase IIRC.
Anton
7-Aug-2009
[14420]
Ok I found them, thankyou Gabriele.
james_nak
7-Aug-2009
[14421]
How do you "read" a network drive in windows? I can a: read %/c/ 
 but when it's a network drive it doesn't work.