Questions tagged [infix-notation]

Operators are written infix-style when they are placed between the operands they act on (e.g. 2 + 2).

Operators are written infix-style when they are placed between the operands they act on (e.g. 2 + 2).

There are a few ways to convert infix to postfix, AKA reverse polish notation.

When working with a recursive descent parser one can factor the grammar.

One can also implement the shunting yard algorithm by Edsger Dijkstra which can be refined into precedence climbing.

540 questions
12
votes
1 answer

Haskell. Why is :info (:) returns the definition twice?

I'm new to haskell. If I type in GHCi (7.10.3): :info (:) I get result: *** Parser: data [] a = ... | a : [a] -- Defined in ‘GHC.Types’ infixr 5 : data [] a = ... | a : [a] -- Defined in ‘GHC.Types’ infixr 5 : Does it means that operator is…
user1201917
  • 1,360
  • 1
  • 14
  • 27
12
votes
1 answer

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative?

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative? (This kind of equivalence is valid in a popular idiom with plain $, but currently $ is right-associative!) <*> has the same associativity and precedence as <$>,…
11
votes
2 answers

How do I write Swift infix functions?

I've seen this done, but I just can't wrap my head around it. Somehow, seemingly magically, some infix functions work fine, but others simply won't compile. For example: As you see here, my then function work as a traditional function, but not as…
Ky -
  • 30,724
  • 51
  • 192
  • 308
11
votes
1 answer

How to give infixities to operators in lambda?

For example, this does not type check \cons nil -> 5 `cons` 3 `cons` nil nor does this \(#) -> 5 # 3 # nil Although both of these do \cons nil -> 5 `cons` nil \(#) nil -> 5 # nil Is there a way to assign infixites to operators in lambdas. I…
PyRulez
  • 10,513
  • 10
  • 42
  • 87
11
votes
2 answers

Why does Scala evaluate the argument for a call-by-name parameter if the method is infix and right-associative?

As I understood call-by-name parameters of a method, the corresponding argument expression will not be evaluated when passing it to the method, but only when (and if) the value of the parameter is used in the method body. In the following example,…
Holger Peine
  • 1,079
  • 1
  • 9
  • 13
11
votes
2 answers

Is it possible to add a method to a built-in type in Scala?

I would like to add a method to a built-in type (e.g. Double), so that I can use an infix operator. Is that possible?
namin
  • 37,139
  • 8
  • 58
  • 74
10
votes
3 answers

C++ infix to prefix conversion for logical conditions

I want to evaluate one expression in C++. To evaluate it, I want the expression to be converted to prefix format. Here is an example wstring expression = "Feature1 And Feature2"; Here are possible ways. expression = "Feature1 And (Feature2 Or…
user90150
9
votes
3 answers

Automatic lifting of infix operators to monadic infix operators

One of the nice things about Haskell is the ability to use infix notation. 1 : 2 : 3 : [] :: Num a => [a] 2 + 4 * 3 + 5 :: Num a => a But this power is suddenly and sadly lost when the operator needs to be lifted. liftM2 (*) (liftM2 (+) m2…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
9
votes
1 answer

How does the scope effect EVAL of an infix:<> sub?

This code works as expected: sub infix:(*@a) { @a.sum / @a.elems } sub Mean (*@a) { @a.sum / @a.elems } say EVAL 'Mean 2, 6, 4'; # Output: 4 say EVAL '2 mean 6 mean 4'; # Output: 4 It works as expected when line 7 is in its own…
Jim Bollinger
  • 1,671
  • 1
  • 13
9
votes
1 answer

Syntax rules for Haskell infix datatype constructors

I'm trying to make a Haskell datatype a bit like a python dictionary, a ruby hash or a javascript object, in which a string is linked to a value, like so: data Entry t = Entry String t type Dictionary t = [Entry t] The above code works fine.…
AJF
  • 11,767
  • 2
  • 37
  • 64
9
votes
6 answers

Convert from an infix expression to postfix (C++) using Stacks

My lecturer gave me an assignment to create a program to convert and infix expression to postfix using Stacks. I've made the stack classes and some functions to read the infix expression. But this one function, called convertToPostfix(char * const…
Reggie Escobar
  • 99
  • 1
  • 1
  • 3
9
votes
4 answers

Transition from infix to prefix notation

I started learning Clojure recently. Generally it looks interesting, but I can't get used to some syntactic inconveniences (comparing to previous Ruby/C# experience). Prefix notation for nested expressions. In Ruby I get used to write complex…
Alexey
  • 9,197
  • 5
  • 64
  • 76
8
votes
3 answers

Scala Map, ambiguity between tuple and function argument list

val m = scala.collection.mutable.Map[String, Int]() // this doesn't work m += ("foo", 2) // this does work m += (("foo", 2)) // this works too val barpair = ("bar", 3) m += barpair So what's the deal with m += ("foo" , 2) not working? Scala gives…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
8
votes
2 answers

In R, how can I determine the operator precedence of user defined infix operators?

Suppose I have two custom infix operators in R: %foo% and %bar%. I have expressions that use both operators, such as: x %foo% y %bar% z How can I determine the operator precedence of %foo% and %bar%? How can I change the precedence so that, for…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
8
votes
1 answer

How to convert user-friendly infix math code to Clojure code?

I want user to be able to input like this: 5+6*t+sin(2*t) , so it will get converted to this: (+ 5 (* 6 t) (sin (* 2 t))) , so I can eval it to some function that will be JITted and executed efficiently later. Are there already available libraries…
Vi.
  • 37,014
  • 18
  • 93
  • 148
1
2
3
35 36