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

World: r4wp

[Rebol School] REBOL School

Endo
28-Aug-2012
[902]
Why this doesn't work?
e: func [] [f]

context [f: does [print "ok"] do bind 'e self] ;error: f has no value

or when I BIND the F inside E, still doesn't work:
o: context [f: does [print "ok"]]
bind first second :e o
e
** Script Error: f has no value

while this one works:
do bind first second :e o
== ok

doesn't F stay BINDed?
DocKimbel
28-Aug-2012
[903]
In your first try (bind 'e self), you're binding only this 'e word, 
not the :e function body, so if you replace it with: bind second 
:e self, it will work.


In second try, you're never binding 'e function body, you've just 
binded a new instance of 'f word that you have created using FIRST. 
That's why it works when you add DO, you're evaluating that new 'f 
instance which has the correct binding. Just remove FIRST, it will 
bind 'e body block and you'll get the result you've expected.

>> e: func [] [f]
>> o: context [f: does [print "ok"]]
>> bind second :e o
== [f]
>> e
ok
Endo
28-Aug-2012
[904]
Got it, thanks a lot. I didn't know that FIRST gives me a "new" word, 
I thought that I'm BINDing *the* word itself and it should stay BINDed.

This confused me a bit:
>> o: context [a: 1 b: 2 c: 3]

>> foreach x bind [a b c] o [probe get x] ;this works, BINDs block 
to O

>> foreach x [a b c] [probe get bind x o] ;this works too, BINDs 
the word 'X to O
DocKimbel
28-Aug-2012
[905x2]
No, it doesn't bind 'x, it binds x, which is evaluated to 'a, 'b 
or 'c.
If you write in the loop: bind 'x o, it will fail, because 'x is 
not defined in o.
Endo
28-Aug-2012
[907x2]
I see, thank you. And in the first line, it doesn't BIND *the block* 
to O, it BINDs the block of words (which are 'a, 'b and 'c) to O. 
It's clear now. Thanks!
Another interesting problem I have: I have a script as follow:
REBOL []
probe system/options/args
halt


I encap this script, no problem, it works as expected, console opens 
and "none" appears:
none
** Press enter to quit...

If I run it with some params like "test.exe --test"
["--test"]
** Press enter to quit... 


But if I run it with some parameters, like -c, --sec, it prints nothing? 
(-c and --sec seems to be special for rebol.exe but it works with 
-s which is special too)
** Press enter to quit...

Why and how PROBE doesn't produce an output?
DocKimbel
28-Aug-2012
[909]
Try with system/script/args instead.
Endo
28-Aug-2012
[910x4]
Let me simplify:

REBOL []
print "ok"
print system/script/args
ask "test"


When I encap this script and run with a parameter like "-cxx" it 
doesn't print ANYTHING.

no "ok" no "test" nothing. BUT when I WRITE system/script/args to 
a file it looks it is there.

REBOL []
print "ok"

write %test.txt system/script/args ;there is "-cxx" in test.txt file.
yes I tried both "options" and "script", same result.
It's very weird, so we don't have a chance to use a parameter starting 
with -c (and many other) in our encapped executables.
More simplified, encap following script, run it with -c, -w or --sec, 
it prints nothing. Run it with -i, -t, -? it prints "ok".
REBOL [] print "ok" halt
DocKimbel
28-Aug-2012
[914]
Might be a bug where encapped REBOL tries to consume its own command-line 
options (while it shouldn't).
Endo
28-Aug-2012
[915x2]
It looks like. I thought that it confusing with REBOL's own command-line 
parameters but it happens only for some of them not for all. So no 
chance to use *some* parameters.
Aha PRINT and PROBE doesn't work in encapped executable if command-line 
parameter includes a "c" character.
DocKimbel
28-Aug-2012
[917]
Any "c" character? I guess then that I was very lucky with Cheyenne: 
http://cheyenne-server.org/wiki/Main/Command
:-)
Endo
28-Aug-2012
[918]
Definitely!! But we should keep that in mind.
sqlab
28-Aug-2012
[919]
-c means cgi ==> So not ouput to the console
BrianH
28-Aug-2012
[920]
Endo, when you are using set-words with MAP-EACH and R3's FOREACH, 
be sure to include at least one regular word, or it won't advance 
and you'll get an endless loop. We made that possible in order to 
support the foreach [x:] data [... take x ...] code pattern. It's 
the type of thing that would generate a warning in other languages, 
but REBOL is inherently incompatible with warnings.
Endo
28-Aug-2012
[921]
BrianH: Yes I realized that at least one word is required.

sqlab: I encap a script and run the executable, so I should able 
to use any command line parameter. And I don't encap with cgi option. 
Also -w parameter has no such a problem (which is "no-window option 
for REBOL)

Anything that include "c" char prevents to print/probe to the console.

On the other hand it doesn't prevent opening console window. I see 
"** Press enter to quit" message when program HALTed but PRINTs don't 
output anything.
GrahamC
4-Sep-2012
[922]
this works, the other two do not

 system/schemes/default/timeout: 0:01:10
 ;system/schemes/http/timeout: 0:01:10
;system/schemes/https/timeout: 0:01:10
Endo
5-Sep-2012
[923]
Confirmed.
Even system/schemes/default/timeout: none
caelum
5-Sep-2012
[924]
A beginners question. I have some code that allows a user to input 
a date or leave it blank;

datetime: field

I get the data by accessing;

datetime/text


My question is, if the user leaves the field empty, how do I test 
for this? I have tried none? And empty?

If none? datetime/text [print "Select a date"]


produces a Script Error: 'datetime has no value'. How do I test if 
datetime/text is null so I can ask the user to go back and fill in 
the datetime field?
Maxim
5-Sep-2012
[925]
a one liner:

until [  view layout [fld: field]    not empty? fld/text ]
Kaj
5-Sep-2012
[926]
You seem to be trying to access datetime outside the VID context, 
where it is not defined
Maxim
5-Sep-2012
[927x3]
here, the field's action compares the field when pressing tab/enter, 
and will close the window when its not empty.


until [view layout [fld: field [unless empty? face/text [unview]]] 
not empty? fld/text]
not that within an action func, you can use  'FACE  to refer to the 
control triggering the action.
not => note
caelum
5-Sep-2012
[930x2]
Maxim thanks for the code. I'll experiment.
Kaj, I think you are right. I'll check to see if that is what's hapening.
GrahamC
5-Sep-2012
[932]
you get that vid error because you are referring to it before the 
layout function has run.
caelum
5-Sep-2012
[933]
GrahamC, It was simpler than that. The program I am working on has 
over 1300 lines of code, and I mis-typed a variable name! So it turns 
out I was trying to access a word that did not exist, was not defined. 
I'll remember that for next time. (Yes, there will be a next time). 
Thanks for all the help. I am beginning to feel competent programming 
in Rebol2.
Sunanda
5-Sep-2012
[934]
Caelem, D'oh moments are possible in any language.
I once wrote
    return: true
rather than
    return true

The protracted debug session that followed taught me the value of 
protect-system.
Arnold
7-Sep-2012
[935]
Hi I am trying to replicate this in Rebol: http://www.alistapart.com/articles/succeed/
I have the redirect setup but I want to know what url the user entered. 
Where can I get $DOCUMENT_ROOT.$REQUEST_URI ??
DocKimbel
7-Sep-2012
[936]
If you are using REBOL in CGI mode:

    get-env "DOCUMENT_ROOT"
    get-env  "REQUEST_URI"
Arnold
7-Sep-2012
[937x2]
Thank you, this works! I found and old conversation on ALTME this 
afternoon but that could not convince me being the answer, this answer 
will replace the old one. (I even typed get_env the first time). 
And for completeness I will write how to use it (cut and paste code) 
requestedurl: get-env "REQUEST_URI"
And the next step get-env "SCRIPT_FILENAME" 
guess I will have to post the complete script when I finish it.
Kaj
7-Sep-2012
[939x2]
These values are already processed by REBOL when it is started in 
CGI mode. I'm using
	cgi: system/options/cgi
The request URI is then in cgi/path-info
The script name is in cgi/script-name or something like that
Arnold
7-Sep-2012
[941x2]
Hi Kaj, wish it was that simple. I have put some strings into action 
and you can view the result here http://arnoldvanhofwegen.com/rebol/doesnotexist.html
Well as you can see path-info is none.
The script name is the script name of the script that is being executed, 
I knew that one already I redirected to it, not the requested page.
Kaj
8-Sep-2012
[943]
Ah, so REBOL does follow the major rule of other software: it does 
everything except the thing you need
Arnold
11-Sep-2012
[944x2]
Found some code/documentation about playing a sound (wav) on www.rebol.com/docs/sound.html 
 

but although rebol/view 2.7.8 (Win XP) has Sound 1.4.0 on board it 
seems using the sound:// port is reserved for use by the SDK version? 
** Access Error: Cannot open sound
** Where: halt-view
** Near: sound-port: open sound://
on MacOSX I get
** Access Error: Invalid port spec: sound://
** Where: halt-view
** Near: sound-port: open sound://

But that is less surprising since there is no Sound module available 
there.
So what is Sound (1.4.0) about?
Kaj is right again
Kaj
11-Sep-2012
[946x2]
Sound in REBOL is primitive, but I thought it had been in the free 
versions for many years
Did you initialise events like the doc says?
Arnold
11-Sep-2012
[948]
could be a rights issue? That the port may not be freely accessible.
Kaj
11-Sep-2012
[949]
That was a long time ago, and it should say "Feature not available 
in this REBOL"
james_nak
11-Sep-2012
[950]
Arnold, I've been using sound in a recent app with 2.7.8.3.1 with 
no issues (on XP too). I use a version of Nick's code http://musiclessonz.com/rebol_tutorial.html.
Look for "play-sound"
Endo
11-Sep-2012
[951]
this works for me on free version of View: (XP)

sound-port: open sound://
play: func [file] [
 wait sound-port
 clear sound-port
 insert sound-port file
 wait sound-port
]