Syntax of &-operator
- Posted by Lutz_Heitmann at NF.MAUS.DE Apr 08, 2001
- 507 views
-P1322@KI Hi Derek, > a & b = append({a}, b) > a & b = append(a, b) > > being valid at the same time! DP>Is the strangeness due it allowing both atoms and sequences in the DP>operands? No, it's the different results '{{a}, b}' or '{a, b}', depending on the data types of a and b. > It could be coded like this: > {a} & {b} & {c} & {d} > DP>or like this ... > DP> {a,b,c,d} > Nope! That would eliminate the option of "&=". DP>How so? DP> sequence x DP> atom a,b,c,d DP> DP> x = {1,2,3,4} DP> a = 91 DP> b = 92 DP> c = 93 DP> d = 94 DP> x &= {a,b,c,d} DP> -- leaves x to be {1,2,3,4,90,91,92,93} Alright, let's assume '@' is the new symbol. In that case I might've written: {a} @ {b} @ {c} @ {d} You propose {a, b, c, d} instead. But then you fall back to x @= {a, b, c, d} which is exactly why I'd rather see a new operator that can be used like '&' and especially like '&='. DP>I suspect that if enough advocacy is used on things that won't break DP>existing code, RDS just might be bothered with it. Its always worth a DP>try. Exactly! DP>And yet, I'm glad of the way that '&' uses both datatypes. The '&'-operator won't be dropped, of course, and it can always be used! DP>Otherwise I'd have to code ugly things like this all the time ... DP> if atom(a) or atom(b) then DP> x = a & b DP> else DP> x = a @ b DP> end if It's the other way round: '@' should eliminate the need for internal type checking and thus be faster. Where external type checking (by your program) is necessary, you should use the more general '&' with its much faster internal check. It's like with objects, atoms, and integers: Declare an object first. Once you know it will always be a number, declare it as a number. And once you know it will always be an integer, declare it as an integer. But if you don't want to worry about atoms or integers, you can stick to objects which still work the same... DP>If you really want a function to do this I suppose you could create ... [...] I'm talking about an operator, not a function! Lutz.