Kim,

You've definitely found something.  I'm likely responsible for the Rosetta page 
you found and wrote it based solely on the example on page 19 of theUnicon 
book. You can see the code generated by the pre-processor by running:

unicon -E xyz.icn

From the example on page 19 of the Unicon book:

procedure succ(i:integer:1)
end


Generates a coercion function (also for string, numeric, and real):

procedure succ(i                      );
/i := 1
i := integer(i) | runerr(101, i)

end


Of course the above doesn't work for types like table (i.e. table(t) ~=== t  
but integer(i) = i; where t is a table and i an integer).  So then for these:

procedure f1(x:table)
end


Generates a type test (also for list, set, userdefinedrecord):

 procedure f1(x       );
(type(x)=="table") | runerr(124, x)

end
Also in the parameter:type:initialvalue syntax, the initial value needs to be a 
constant (I 
tried unsuccessfully to trick it with a pre-processor definition.

There appears at this time to be no way to do any of these:
        * procedure f1(x:table|set|list) # as you observed
        * procedure f2(x:mycoercion:1)   # as you observed 

        * procedure f2(x:table:table())  # as I found (either directly or 
indirectly)


The ability to have your own type coercion function would be very 
useful.  It seems I read more into the description than was really there. The 
behaviour could be changed but this would require altering the code generated 
by Unicon.  For instance image() can distinguish between the various forms in 
ways type can't.  But now we are talking about an enhancement.


Hope this helps.


David





>________________________________
> From: Kim Bastin <[email protected]>
>To: [email protected] 
>Sent: Wednesday, July 18, 2012 10:27:40 PM
>Subject: [Unicon-group] Procedure Parameter Type Casting
> 
>At 
>http://rosettacode.org/wiki/Icon%2BUnicon/Intro#Procedure_Parameter_Type_Casting
> 
>the following example is given:
>
>procedure f1(i:integer:1,r:real,s:string,L:list,x:mycoercionproc)
>
>Comments/queries:
>
>(1) I can’t find any formal documentation of this feature. Is it defined
>anywhere?
>
>(2) Experimentation indicates that the only things allowed after the
>“:” are data types (integer, real, string, list etc.). I have been 
>unable to create any customised coercion function (as mycoercionproc in 
>the example above) that the compiler will accept.
>
>(3) In a case like
>
>procedure f1(T:table)
>
>what does “:table” actually do? You can convert a real or (sometimes) a
>string to an integer, but can you convert anything to a table that isn’t 
>already a table? In this case, the function of “:table” seems to be just 
>type checking.
>
>(4) If I’m right on (3), consider this example from the Unicon book (p39):
>
>procedure complete(prefix, filenames)
>   suspend match(prefix, p := !filenames) & p
>end
>
>This works equally well whether filenames is a list (as assumed in the
>text), a table, or a set. But there is no way one can use the feature 
>under discussion to check that it is one of these: anything like
>
>procedure complete(prefix:string, filenames:list|table|set)
>
>is rejected by the compiler.
>
>However, in the absence of documentation I may be simply misled about
>what this feature is supposed to do.
>
>Thanks for help
>Kim
>
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and 
>threat landscape has changed and how IT managers can respond. Discussions 
>will include endpoint security, mobile security and the latest in malware 
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>_______________________________________________
>Unicon-group mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/unicon-group
>
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to