[REBOL] [REBOL] Default Port Values? Re:(3)

2000-05-24 Thread agem


Want to add: 
You can 'probe for tracing,
 safe-close: func [p][if probe p  [] [close probe p]]
'probe will show you the values without modifying something.
good if one mistake content or the error-position.

(thanks for the more specific answers for inits :)

Volker

 Hi Ladislav:
 Yes, your code works for me. But I wrote a function
 as follows:
 safe-close: func [p[port!]][if p [close p]]
 lets say  
 dufus: none
 safe-close dufus
 generates
 Script Error: safe-close expected p argument of type: port
 HOWEVER:
 if I write 
 safe-close: func [p][if p  [] [close p]]
 dufus: []
 safe-close dufus
 I get no error message.
 :) Duh!! I know I have lots to learn yet.
 Thanks
 Tim
 Sorry, I don't understand. For me your code works:
 
  dufus-pointer: none
 == none
  either equal? dufus-pointer none [][close dufus-pointer]
 
 
 Ladislav
 
 
 
 
 




[REBOL] [REBOL] Default Port Values? Re:

2000-05-23 Thread lmecir

Hi, 

Tim wrote:

 I'm setting up an object that contains some ports,
 which may or may not be open. 
 i.e.: may or may not open "test.txt"
   may or may not open "dufus.txt"
 obviously I don't want to attempt to close
 what I didn't open.
 If I initialize a word to none
 as dufus-pointer: none
 and don't open it.
 the following code:
 either equal? dufus-pointer none [][close dufus-pointer]
   generates an error: expected argument of type: port
 
 similarly a function like
 safe-close: func [p[port!]][if p [close p]]
 
 generates an error message.
 
 How can I get around this?
 
 
 Thanks Folks!
 Tim
 
 

Sorry, I don't understand. For me your code works:

 dufus-pointer: none
== none
 either equal? dufus-pointer none [][close dufus-pointer]


Ladislav




[REBOL] [REBOL] Default Port Values? Re:

2000-05-23 Thread icimjs

Hi Tim,

1. safe-close:

similarly a function like
safe-close: func [p[port!]][if p [close p]]

generates an error message.

Since you only permit port! as the argument's datatype, and none is of type
none! and not port!, you shouldn't be too surprised! ;-)

Try 

safe-close: func [p[port! none!]][if p [close p]]

 safe-close: func [p[port! none!]][if p [close p]]
 safe-close dufus-pointer
== false

2. equal? dufus-pointer none ...
max's idea, to use port?, should certainly work (and is the cleaner way to
do it anyway).

It bothers me, however, that your code fails. The code you present should
work as expected, as can easily be tested in the REBOL shell:

 dufus-pointer: none
== none
 equal? dufus-pointer none
== true

I can think of three reasons why this could happen:
1. the error is not being generated by the code you presented;
2. dufus-pointer is being set (unexepctedly!) to some non-port value
somewhere in your program. This possibility should worry you! ;-)
3. One of the two none values is not a none value. It is a word value. For
instance:
 a: none
== none
 b: first [none]
== none
 none? a
== true
 none? b
== false
 type? a
== none!
 type? b
== word!


At 08:44 PM 5/22/00 -0800, you wrote:
I'm sending this again Are we having problems with
the mailing list again?
==
I'm setting up an object that contains some ports,
which may or may not be open. 
i.e.: may or may not open "test.txt"
  may or may not open "dufus.txt"
obviously I don't want to attempt to close
what I didn't open.
If I initialize a word to none
as dufus-pointer: none
and don't open it.
the following code:
either equal? dufus-pointer none [][close dufus-pointer]
  generates an error: expected argument of type: port

similarly a function like
safe-close: func [p[port!]][if p [close p]]

generates an error message.

How can I get around this?


Thanks Folks!
Tim




;- Elan  [: - )]




[REBOL] [REBOL] Default Port Values? Re:(2)

2000-05-23 Thread tim

Hi Ladislav:
Yes, your code works for me. But I wrote a function
as follows:
safe-close: func [p[port!]][if p [close p]]
lets say  
dufus: none
safe-close dufus
generates
Script Error: safe-close expected p argument of type: port
HOWEVER:
if I write 
safe-close: func [p][if p  [] [close p]]
dufus: []
safe-close dufus
I get no error message.
:) Duh!! I know I have lots to learn yet.
Thanks
Tim
Sorry, I don't understand. For me your code works:

 dufus-pointer: none
== none
 either equal? dufus-pointer none [][close dufus-pointer]


Ladislav






[REBOL] [REBOL] Default Port Values? Re:(2)

2000-05-23 Thread tim

Hi Max:
That is very good advice. I keep forgetting to make
use of rebol's run-time type checking.
That is a very nice feature!
Thanks
Tim
At 10:10 PM 5/22/00 -0700, you wrote:
If port? dufus-pointer [  ]





[REBOL] [REBOL] Default Port Values? Re:(3)

2000-05-23 Thread icimjs

Hi Tim,

Here
safe-close: func [p[port!]][if p [close p]]

you are insisting that the argument to safe-close must be a value of
datatype port!, [ p [port!] ]. Therefore you get an error message, whenever
you pass a value that is not of type port!.

In contrast, here

safe-close: func [p][if p  [] [close p]]

you are not declaring a type restriction on the values passed to
safe-close, [ p ]. Accordingly, safe-close does not complain that the value
is not of type port!. 

Confusing? Not really.

At 08:22 AM 5/23/00 -0800, you wrote:
Hi Ladislav:
   Yes, your code works for me. But I wrote a function
as follows:
safe-close: func [p[port!]][if p [close p]]
lets say  
dufus: none
safe-close dufus
generates
Script Error: safe-close expected p argument of type: port
HOWEVER:
if I write 
safe-close: func [p][if p  [] [close p]]
dufus: []
safe-close dufus
I get no error message.
:) Duh!! I know I have lots to learn yet.
Thanks
Tim
Sorry, I don't understand. For me your code works:

 dufus-pointer: none
== none
 either equal? dufus-pointer none [][close dufus-pointer]


Ladislav






;- Elan  [: - )]




[REBOL] [REBOL] Default Port Values? Re:(2)

2000-05-23 Thread tim

Hi Elan:
Perhaps it is better to ask this question:
What would be the preferred way to initialize a port
prior to a possible open?
would it best to be:
my-port: none
OR
my-port: 
;==
It bothers me, however, that your code fails. The code you present should
work as expected, as can easily be tested in the REBOL shell:

 dufus-pointer: none
== none
 equal? dufus-pointer none
== true

I can think of three reasons why this could happen:
1. the error is not being generated by the code you presented;
2. dufus-pointer is being set (unexepctedly!) to some non-port value
somewhere in your program. This possibility should worry you! ;-)
3. One of the two none values is not a none value. It is a word value. For
Your concern is duly noted: If you're worried, I'm worried. 
Perhaps type? checking is the best way to go
regards
tj