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

World: r3wp

[Core] Discuss core issues

BrianH
27-Jul-2009
[14347x2]
Saw a new language the other day that has a native, literal data 
structure which matches the XML object model, without the syntax.
Nice language - clean and small, pretty to look at, compiles to native 
code.
Graham
27-Jul-2009
[14349x3]
Given 


>> obj: make object! [ Description: make object! [ Text: "REBOL" 
]]
>> path: 'Description/Text
== Description/Text


How can I find "REBOL" without breaking the path into it's constituents?
I'm guessing that there's something very simple ... but in the meantime


get-value: func [ obj [object!] path [path!]
	/local id
][
	if not empty? path [
		either all [ id: in obj path/1  obj: get id  object? obj ][
			remove path
			get-value obj path
		][
			obj
		]
	]
]
>> get-value obj path
== "REBOL"
Ashley
29-Jul-2009
[14352x2]
Is this a bug or a feature:

>> to integer! ""
== 0
>> to decimal! ""
** Script Error: Invalid argument:
** Near: to decimal! ""
Henrik
29-Jul-2009
[14354]
R3 returns a bug with the first one, but it could be intentional 
in both R2 and R3.
BrianH
29-Jul-2009
[14355]
It was an intentional change. TO has been cleaned up a lot in R3 
- the error there tells why:
>> to integer! ""
** Script error: content too short (or just whitespace)
Sunanda
29-Jul-2009
[14356x2]
R2 also works with
  to integer! #
but  not
  to integer! %
Looks like a consistency bug in R2 that has been fixed in R3.
Oops -- Brian beat me to, and gave the definitive answer to trump 
my late speculation.
BrianH
29-Jul-2009
[14358x2]
The R2 behavior is more of a "feature": Buggy behavior that you can 
count on remaining in R2 for compatibility reasons.
Almost every day I come across another reason to appreciate bug#666 
:)
Graham
4-Aug-2009
[14360x2]
How can i redefine 'now so that it takes into account an offset ( 
which is only calculated once ) .. without causing a stack overflow!
I guess I need to copy the function block of 'now ... but can you 
do that with natives ?
BrianH
4-Aug-2009
[14362x2]
SPEC-OF works on natives too :)
Remember to keep a private reference to the old NOW, or at least 
reference it through system/contexts/system/now. When you set 'now 
in a user script it will copy the value of 'now to the user context 
(system/contexts/user), and then you will be reassigning it there.
Graham
4-Aug-2009
[14364x2]
spec-of ??
sounds like a R3 function
BrianH
4-Aug-2009
[14366x4]
Oh, sorry, I backported it. Try this instead:
    copy/deep third :now
I forget sometimes when R2 doesn't have the new functions since I 
mostly work with R2/Forward (the backports).
And isnore the user-vs-system context thing too.
isnore -> ignore
Graham
4-Aug-2009
[14370]
you're having a dyslexic day :)
BrianH
4-Aug-2009
[14371]
Bad typing day :(
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 ...