[chuck-users] "pure"

Andrew Turley aturley at acm.org
Sat May 9 16:48:55 EDT 2009


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
>


More information about the chuck-users mailing list