[chuck-users] "pure"

Ge Wang ge at ccrma.Stanford.EDU
Sun May 10 01:50:44 EDT 2009


Greetings!

"pure" is short for "pure virtual", which is similar to method prototypes 
in Java interfaces, abstract Java methods, or pure virtual functions in 
C++ (denoted by the "= 0" at the end of a member function declaration).

This feature is, not surprisingly, not yet fully implemented in ChucK.

Mostly, the motivation for "pure" is so you can end up with function 
declarations that start with the string "pure fun".

The dangers of name-driven research...

Ge!

On Sat, 9 May 2009, Robert Poor wrote:

> I need to know: How did Tom find out about the "pure" keyword in the first 
> place?  By consulting the "authoritative documentation" [i.e. chuck_type.cpp 
> :)]?  Is reading the source code the only way to learn about these things? 
> (Ditto for "interface"...)
>
> As an aside, I appreciate the value of "programming by contract" constructs.
>
> - Rob
>
> On 9 May 2009, at 13:48, Andrew Turley wrote:
>
>> If I didn't know any better (and I don't) I would guess that calling a
>> method "pure" is a way of indicating that any class that implements X
>> must provide a function called "doit()", but that X will not provide a
>> default implementation of that method. It forces the child class to
>> provide the implementation.
>> 
>> If you wrote:
>> 
>> class X {
>>  fun void doit() {};
>> }
>> 
>> and then created a class Y that extends class X, Y would not have to
>> provide an implementation of "doit()". Take a look at pure virtual
>> classe in C++, interfaces in Java, or abstract classes in general.
>> 
>> One of the uses for pure function is to help with "programming by
>> contract" where other methods and functions will accept objects that
>> are guaranteed to provide *some* implementation of a method, without
>> making any claims about what that method will do.
>> 
>> andy
>> 
>> On Sat, May 9, 2009 at 12:38 PM, Tom Lieber <lieber at princeton.edu> wrote:
>>> class X {
>>>   fun void doit();
>>> }
>>> 
>>> [Untitled]:line(2): function declaration must contain code...
>>> [Untitled]:line(2): (unless in interface, or is declared 'pure')
>>> [Untitled]:line(2): ...at function 'doit'
>>> 
>>> interface X {
>>>   fun void doit();
>>> }
>>> 
>>> [Untitled]:line(2): function declaration must contain code...
>>> [Untitled]:line(2): (unless in interface, or is declared 'pure')
>>> [Untitled]:line(2): ...at function 'doit'
>>> 
>>> class X {
>>>   fun pure void doit();
>>> }
>>> 
>>> [chuck](VM): sporking incoming shred: 1 (Untitled)...
>>> 
>>> Does anybody use "pure" or know what it does? The last example seems
>>> to be equivalent to saying "fun void doit() { }".
>>> 
>>> --
>>> Tom Lieber
>>> http://AllTom.com/
>>> _______________________________________________
>>> chuck-users mailing list
>>> chuck-users at lists.cs.princeton.edu
>>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>> 
>> _______________________________________________
>> chuck-users mailing list
>> chuck-users at lists.cs.princeton.edu
>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users


More information about the chuck-users mailing list