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

World: r4wp

[Rebol School] REBOL School

Gregg
27-Apr-2012
[152x2]
date-to-epoch: func [
    "Returns a unix time (epoch) format from a date."
    date [date!]
][
    ; If no time is given, negate our zone to give us 0:00 UTC
    if none? date/time [date/time: negate now/zone]
    ; This uses the epoch base in UTC, so we assume that either
    ; the date is also in UTC, or has a zone offset included.
    ; DIFFERENCE fails for huge time differences, so we subtract
    ; them instead, giving us a difference in days, and multiply
    ; by the number of seconds in a day.

    either attempt [positive? res: to integer! difference date 1-Jan-1970/0:0:0] 
        [res]
        [date - 1-Jan-1970/0:0:0 * 86400.0]
]
I believe the reason I still have DIFFRENCE in there, as far as it 
will work, is for greater accuracy. I don't remember why I have the 
zone negation bit in there, but I probably hit some issue that required 
it.
GrahamC
27-Apr-2012
[154x3]
@endo ... using math is fasting than padding with leading zeroes
fasting => much faster
eg.  next form 100 + now/day

will give you 2 digits, and those less than 10 will have a leading 
zero
Endo
27-Apr-2012
[157]
Thank you guys.
DIFFERENCE fails when it reaches integer limits,
>> to-integer difference 19-jan-2038/3:14:08 1-Jan-1970/0:0:0
== -2147483648
>> ? -2147483649
== decimal!
I think it will be a Y2K problem for Unix systems.
Sunanda
27-Apr-2012
[158]
A similar  problem has been reported in the past, and dismissed -- 
so not considered a bug by the developers:
   http://curecode.org/rebol3/ticket.rsp?id=1767&cursor=12
Endo
27-Apr-2012
[159]
In Carl's example one of the numbers should be decimal, otherwise 
it gives overflow error:
24.0 * 60 * 60 * subtract 1-jan-2000 1-jan-2100
or 86400.0 * subtract 1-jan-2000 1-jan-2100
Gabriele
27-Apr-2012
[160]
R2 is only 32 bits :-)
Evgeniy Philippov
28-Apr-2012
[161x4]
Could anyone tell, Is rebol a language for sketching systems, or 
is it a full-fledged Turing-full language with access to all machine's 
resources? Seems to be a sketching one, IMHO. Could anyone comment 
on this?
Not intending to start a religious war, but it's interesting what 
opinions about such and other qualities of rebol people have.
I have almost zero experience at programming in rebol.
Or is Rebol an OverForth type language which is too syntactically 
*liquid* to use in long-term industrial and long-term stable projects? 
Could anyone comment?
Gregg
28-Apr-2012
[165]
REBOL is a full-fledged, high-level language. I use it for commercial 
work. R2 is very stable, but does have a small number of things that 
may never be fixed. Only you can say if they would cause you problems. 
The bigger issue is that RT doesn't seem to be maintaining REBOL 
anymore. The hope is that Red, World, and others will mature enough 
to be viable options.
Henrik
28-Apr-2012
[166]
rebol a language for sketching systems

 - nevertheless, REBOL is also excellent for prototyping things that 
 need to be done in another language.
Sunanda
28-Apr-2012
[167]
REBOL is structured more like LISP or Haskell (but without being 
a pure functional language).


So, yes, it does not have direct access to the machine instructions 
or low-level op sys APIs in the way that assembler or assembler-wrapper 
languages (like C) does.


What REBOL does have is easy integrated access to very high level 
APIs: parse. bind, map, etc.
Sujoy
3-May-2012
[168]
beginner question:
i'm opening a file using
    d: open/direct/lines %bigfile.nt
i am then looping through each line using:
    while [ln: first d] [ ;do something here ]

i need to record the byte position of the start and end of each line...
how?
PeterWood
3-May-2012
[169]
I think you will have to calculate them yourself using length? ln 
and adjust for newline/cr as appropriiate.
Sujoy
3-May-2012
[170x3]
thanks Peter...

i can find the length? of each line, but how do i calculate the length 
of the newline?
>> length? to-string #"^/"
== 1
>> length? to-string crlf
== 2
how do i detect the newline used in %bigfile.nt?
Maxim
3-May-2012
[173]
hahaha I was writing exactly about this.
Sujoy
3-May-2012
[174]
:)
Maxim
3-May-2012
[175x2]
basically... just find crlf in the file.
if you find one, you can assume its using crlf format for newlines.
Sujoy
3-May-2012
[177x2]
ok...
trying that now...
p.s.: any luck with the new mod-api release?
Maxim
3-May-2012
[179x2]
you can always try using /binary, but I don't know how it relates 
to using /lines.  IMO if you use /lines, the /binary refinement doesn't 
make a lot of sense
wrt mod-api... yes, and no, I was temporarily assigned to another 
project, but should get back to it tomorow, so I hope to have a release 
next week.
PeterWood
3-May-2012
[181x2]
how do i detect the newline used in %bigfile.nt?

 - you can read the first line from the port to work out it's length 
 and then read the fiirst line + the two subsequent bytes in binary 
 mode to check whether they are lf + first char of second line or 
 cr +lf.
This might help you get started:

>> d: open/direct/lines %system-use-case-list.html
>> ln-d: length? ln: first d
== 6
>> ln+nl: read/binary/part %system-use-case-list.html ln-d + 2
== #{3C68746D6C3E0D0A}
Sujoy
3-May-2012
[183x3]
cool - look forward to it maxim
thanks Peter
not sure i've got it though
>> p: open/direct/lines %benchmark_250k.nt
>> ln-d: length? ln: first p
== 195
>> ln+nl: read/binary/part %benchmark_250k.nt ln-d + 2
== #{
3C687474703A2F2F777777342E7769776973732E66752D6265726C696E2E6465
2F62697A65722F6273626D2F7630312F696E7374616E6365732F50726F64...
>> print to-string ln+nl

<http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType1>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#t

ype> <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/ProductType>
.
<
so there is a newline + the first character of the next line
PeterWood
3-May-2012
[186]
To visually check better to print the binary ie
	print ln+nl
Sujoy
3-May-2012
[187]
if i do this:

>> length? find ln+nl newline
== 2


...but how do i detect that the newline in this case has length 1?
PeterWood
3-May-2012
[188]
Something like this should work:

>> ;; position at 2nd last char of ln+nl
>> ln+nl: back back tail ln+nl
== #{0D0A}
>> ;; see if the first of the two chars is a linefeed
>> either #"^(0a)" = first ln+nl [size-nl: 1] [size-nl: 2]
== 2
Sujoy
3-May-2012
[189x2]
super!! Thanks Peter!
just so i remember:
>> print to-binary cr
#{0D}
>> print to-binary crlf
#{0D0A}
>> print to-binary lf
#{0A}
Kaj
3-May-2012
[191]
Watch out for text files that are edited on Windows and other systems 
and end up mixing different newlines
Sujoy
3-May-2012
[192x2]
I was just cracking my head over that Kaj...
will have to look for another way i guess :(
Kaj
4-May-2012
[194x2]
It can still be done, but you have to look for all possible newline 
combinations
If you can control your environment, you could mandate an editor 
that does automatic conversion
GiuseppeC
6-May-2012
[196]
where I am wrong ?

I have an object called news
news/tittle: "Something"
news/data: 06-may-2012

I want to display these data using VID

view layout [
	h2  news/tittle
	h2  news/date
]

news/tittle is displayed
news/date is not

Where I am wrong ?
Henrik
6-May-2012
[197x2]
I have an object called news
news/tittle: "Something"
news/data: 06-may-2012

you did not use /DATA as a typo?
also, it may be that H2 does not support dates as input
GiuseppeC
6-May-2012
[199x3]
yes, it is a Typo
to-string news/date solves the problem
txt does not support DATES too