Hi,
Just an after thought.
Are you aware that _ can be used elsewhere too?
For example, if you have a procedure that takes 4 arguments, and returns
values in the last two,
i.e.
proc {SomeProc A B ?C ?D}
....
end
but for some reason you only want the value that would be returned in D,
you can call it with
{SomeProc 1 2 _ X}
the value that would have been returned in position C is ignored (we
'don't care' what it is) and the value from position D is bound to X.
Hope this helps.
Regards
Mark
mark richardson wrote:
Hi,
Quirino Zagarese wrote:
Ok, I did some tests and I think I got it.
The _ seems to exhibit two different behaviours: if you use it in
pattern matching by itself, its semantic is "anything";
if you combine it with symbols like | or #, its semantic is "any symbol".
It's behaviour doesn't change at all. _ will always means 'anything' -
in our course last year we found it easier to think of it as being the
'don't care' symbol - we 'don't care' what it is.
declare
fun{MatchAll X}
case X of _ then true
else false
end
end
So this means 'If X matches 'don't care' return true'.
X=nil ---------->true
X=1|2|nil|1 --->true
Combining _ for real world pattern matching (_ by itself doesn't make
sense)
declare
fun{MatchIt X}
case X of _|1 then true
else false
end
end
and this means 'match X to the pattern 'don't care'|1 so anything
that can be matched to this pattern returns true.
For example,
X='this is an atom'|1 --> true
X="and this is a string"|1 --> true
X=("this is a really"|'confusing mix')|1 --> true
X=nil|1 ---------->true
X=(1|2|nil)|1 --->true
X=1|2|nil|1------>false
Is this the expected behaviour?
Thank you, I'm understanding a lot of things :-)
Regards
Regards
Mark
2009/2/13 Raphael Collet <[email protected]
<mailto:[email protected]>>
On Fri, Feb 13, 2009 at 2:42 PM, Quirino Zagarese
<[email protected] <mailto:[email protected]>>
wrote:
Thank you very much Raphael,
I though only procedures could use parameters in that way.
This is true. But functions in Oz are defined as procedures,
that's why it works ;-)
Now it's all clearer.
Then what about matching whatever#true? Is there a way to do
that(i.e. a character like % in SQL)?
The identifier '_' matches anything, for instance:
case Result of _#true then ... end
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected] <mailto:[email protected]>
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
Quirino Zagarese
LaszloItalia Founder (www.laszloitalia.org <http://www.laszloitalia.org>)
Software Development Manager - Galilaeus s.r.l.
------------------------------------------------------------------------
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
Mark Richardson
Final year undergraduate
University of Teesside
------------------------------------------------------------------------
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
Mark Richardson
Final year undergraduate
University of Teesside
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users