Ticket #29 (closed defect: duplicate)

Opened 2 years ago

Last modified 11 months ago

a+ b performs (juxtaposition) multiplication, not addition

Reported by: djb Owned by: sukyoungryu
Priority: major Milestone:
Component: interpreter Version: 1.0
Keywords: postfix juxtaposition + plus operator precedence Cc: David.Biesack@…

Description

The following program

export Executable run(args:String...) :() = do

a = 3 b = 10 println ("a=" a ", b=" b) c = a+ b println ("a+ b=" c) d = a + b println ("a +b=" d) e = a+b println ("a+b=" e)

end

produces the output

a=3, b=10 a+ b=30 a +b=13 a+b=13

It appears that the expression

a+ b

is doing multiplication due to juxtaposition of the "expression" (a+) and (b). However, I cannot find a reference to a postfix + operator in the LRM. Sorry if it is there and I missed it. However, if intentional, this does feel counterintuitive.

I'm using code from Subversion, updated todat (Oct 31, 2007)

Attachments

plus.fss Download (194 bytes) - added by djb 2 years ago.
source program

Change History

Changed 2 years ago by djb

source program

Changed 2 years ago by djb

sorry for the unformatted source in the original report. Use the attached source.

Changed 2 years ago by dr2chase

It's highly likely that this is an artifact of bug #16 -- "a+ b" is probably parsing as

(juxt  (postfix+ a) b)

but then the postfix+ is identical to prefix+, which is identity.

Changed 2 years ago by jmaessen

Bug #16 is indeed part of the problem. However, it is at best dubious to parse in this way; if we have a known lower-precedence operator used in prefix or postfix form within a juxtaposition, we probably ought to reject. The interesting question is how we distinguish, eg, prefix + and - from (say) postfix ! so that we can still write k! (n-k)! / n! and the like.

Changed 2 years ago by jmaessen

  • owner changed from dr2chase to sukyoungryu

Changed 2 years ago by djb

  • cc David.Biesack@… added

Changed 2 years ago by sukyoungryu

  • status changed from new to closed
  • resolution set to duplicate

In Fortress, "a +b" is a static error and "a+ b" is parsed as a loose juxtaposition of "a+" and "b" and "a+" is parsed as a postfix operator application. The asymmetry in handling "a +b" and "a+ b" is intentional because it is often to use an operator as both infix and prefix but not as both infix and postfix. For example, "-" is often used as both infix and prefix operator.

Now, this ticket is reduced to Ticket #16. I'm closing this ticket.

Note: See TracTickets for help on using tickets.