|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
|
|
|
Re: [fricas-devel] Re: "has" in the interpreterOn Wed, Nov 19, 2008 at 12:31 PM, Ralf Hemmecke wrote:
> ... > But it shows that 'is'/'has' might lead to lots of branches and thus > the code doesn't scale very well. > > But look at > > mygcd(R: EuclideanDomain)(a: R, b: R): R == { > R has Field => if zero? a and zero? b then 0 else 1; > while not zero? b repeat { (a, b) := (b, a rem b) } > return a; > } > > That I consider a case where 'has' is useful. > I agree. I am not arguing against such usage. It seems to me that when 'has' refers to a category this tells us a lot about the user's intentions (i.e. it is good documentation) and because categories are (usually) rather large things, it is unlikely that we will see a lot of branching code. 'is' however is something else. It invites the programmer to deal with specific cases rather than the most general case. > ... Regards, Bill Page. _______________________________________________ Aldor-l mailing list Aldor-l@... http://aldor.org/mailman/listinfo/aldor-l_aldor.org |
|
|
Re: [fricas-devel] Re: "has" in the interpreter> 'is' however is something else. It invites the programmer to deal with
> specific cases rather than the most general case. I'd would discourage 'is' for such a case. In some experimental code, I had myself some need of 'is' in Aldor. Since there is no 'is' I used some workaround. Here I don't need it for selecting special cases, but rather to check whether the domains are identical so that I could safely 'pretend' that one value 'y' of type Y is also of type X. Instead of the line if List X has ListType Y then { you should read if X is Y then { . I don't say that I am completely happy with the code at all, since 'Object' as presented in the AUG is not really one of my favourite types. (Same for Any, but this is a another story.) Ralf --- define ObjectLabelType: Category == with { LabelType; label: (Lab: LabelType, Lab) -> %; explode: % -> (Lab: LabelType, Lab); } Label: ObjectLabelType == add { macro LT == LabelType; Rep == Record(LabDom: LabelType, label: LabDom); import from Rep; label(Lab: LabelType, l: Lab): % == per [Lab, l]; explode(x: %): (Lab: LabelType, Lab) == explode rep x; equals?(X: LT, x: X)(Y: LT, y: Y): Boolean == { -- We must check whether X is the same domain -- as Y. We can do that by asking whether if List X has ListType Y then { (x = y pretend X) } else { false; } } (x: %) = (y: %): Boolean == equals?(explode x)(explode y); ... } _______________________________________________ Aldor-l mailing list Aldor-l@... http://aldor.org/mailman/listinfo/aldor-l_aldor.org |
|
|
Re: [fricas-devel] Re: "has" in the interpreterOn Wed, Nov 19, 2008 at 3:30 PM, Ralf Hemmecke wrote:
> > In some experimental code, I had myself some need of 'is' in Aldor. > Since there is no 'is' I used some workaround. > > Here I don't need it for selecting special cases, but rather to check > whether the domains are identical so that I could safely 'pretend' > that one value 'y' of type Y is also of type X. > > Instead of the line > if List X has ListType Y then { > you should read > if X is Y then { > . I do not understand. If two domains are identical than why is there any need to "pretend" that they are the same? Regards, Bill Page. _______________________________________________ Aldor-l mailing list Aldor-l@... http://aldor.org/mailman/listinfo/aldor-l_aldor.org |
|
|
|
|
|
Re: [fricas-devel] Re: [fricas-devel] Re: "has" in the interpreterOn 11/19/2008 10:22 PM, Bill Page wrote:
> On Wed, Nov 19, 2008 at 3:30 PM, Ralf Hemmecke wrote: >> In some experimental code, I had myself some need of 'is' in Aldor. >> Since there is no 'is' I used some workaround. >> >> Here I don't need it for selecting special cases, but rather to check >> whether the domains are identical so that I could safely 'pretend' >> that one value 'y' of type Y is also of type X. >> >> Instead of the line >> if List X has ListType Y then { >> you should read >> if X is Y then { >> . > > I do not understand. If two domains are identical than why is there > any need to "pretend" that they are the same? You removed too much from my mail (at least if I understand your question correctly). equals?(X: LT, x: X)(Y: LT, y: Y): Boolean == { if List X has ListType Y then { (x = y pretend X) } else { false; } } equals? works on 4 things. X and Y are domains which both belong to category LT. Now, my construction is a workaround for the missing 'is' and therefore the compiler (after having interpreted 'List X has ListType Y') is not (yet) smart enough to figure out that X and Y are identical and in the 'then' branch y could actually equally be considered to be of type X (without 'pretend'). If 'is' were part of the (Aldor-)language, then of course, inside the 'then' branch the compiler should not require 'pretend', i.e. 'x=y' should just work. But we speak in dreams here. The only thing mentioned about 'is' in the AUG is that it is a reserved keyword. Ralf _______________________________________________ Aldor-l mailing list Aldor-l@... http://aldor.org/mailman/listinfo/aldor-l_aldor.org |
| Free embeddable forum powered by Nabble | Forum Help |