On 7/26/05, Gerard Cote <[EMAIL PROTECTED]> wrote:
>=20
> Hello list members,
>=20
> I just asked myself why my code no more worked well when I inserted some
> query using the ask or input instructions.
>=20
> Before the insert the code was working correctly even if I I transfered i=
t
> to the open console (View 1.3.1) using CUT AND PASTE from
> my editor's window. When I added an ask or an input to stop the running
> script, REBOL then considered the entry completed - probably
> due to the implicit NEWLINE that exists between the lines - and never rea=
lly
> asked me to type something as an entry to my ask
> instruction.
>=20

If i understand that correctly, you want to enter multiple lines until
the input "makes sense" as rebol code? as the console-input does? So
that you can copy/paste to console?

if, below is a quick hacked function.

Also you mentioned to stop the script to ask something.
Note that there is system/ports/input, and you can wait on it.
That can be used like this:
 ; this halts at a specific point if a key was pressed
 if wait[system/ports/input 0][halt]

; the function:
; asks lines until a complete rebol-entry is entered,
; attention: returns all in a block!, even single values.
; limitation: can not decide between finished expression
; and expression with syntax-error. just checks if 'load fails
; thats why stop-token is supported(line with only"~q").=20
; returns then none, not a block.

ask-value: func [msg /local buf xmsg new val %#] [
=09buf: copy ""
=09xmsg: {("~q" aborts)}
=09prin [xmsg msg]
=09forever [
=09=09append append buf new: input newline
=09=09if "~q" =3D new [return none]
=09=09if all [
=09=09=09attempt [val: load/all buf]
=09=09=09[] <> val
=09=09] [
=09=09=09break
=09=09]
=09=09prin [xmsg "more >"]
=09]
=09val
]

; demo
forever [
=09print now
=09awoken: wait [system/ports/input 1]
=09if same? system/ports/input awoken [
=09=09probe do probe ask-value "Test >"=20
=09]

]> To remedy to this situation I have to save my code to a file script (.r)=
 and
> execute this new script using do. Then it works but I
> simply asks myself if there is no other way to control the ask behaviour =
to
> normally process the script as the DO is doing itself.
>=20
> Is there not some magic switch that REBOL uses to control this facet of l=
ife
> ?
>=20
> Below is some code to illustrate the faulty behaviour (to my eyes):
>=20
> Every comment is appreciated,
> Regards,
> Gerard
>=20
> CODE
> =3D=3D=3D=3D=3D
>=20
> crit: "file"
> crit: ask "Enter your own criterion? "
> print "own label"                                 <-- none or one Newline
> can be inserted here
> print crit                                                    after the l=
ine
> containing the ask
>=20
>=20
> Try #1:   No newline after the ask
> =3D=3D=3D=3D=3D
> >> crit: "file"
> =3D=3D "file"
> >> crit: ask "Enter your own criterion? "
> Enter your own criterion? print "own label"     <-- when no Newline is
> present
> =3D=3D {print "own label"}                                          REBOL
> considers the next line
> >> print crit                                                          as
> the string entered by the user
> print "own label"
>=20
> Try #2:   One newline after the ask
> =3D=3D=3D=3D=3D
> >> crit: "file"
> =3D=3D "file"
> >> crit: ask "Enter your own criterion? "
> Enter your own criterion?                            <-- Here the Newline=
 is
> considered by REBOL
> =3D=3D ""                                                                =
as the
> end of the ask and this means the "" is
> >> print "own label"                                            returned =
as
> the new value of the crit word.
> own label
> >> print crit
>=20
>=20
>=20
> --=20
> To unsubscribe from the list, just send an email to=20
> lists at rebol.com with unsubscribe as the subject.
>=20
>=20


--=20
-Volker

"Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem." David
Wheeler
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to