Skip to main content
edited tags
Link
Alexey Popkov
  • 62.5k
  • 7
  • 163
  • 405
added 253 characters in body; edited tags
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

Repeated string pattern: difference between front endthe FrontEnd and WolframScript?

This code works fine in a string based interface like WolframScript: or Mathematica Kernel.

Run this through a string based interface

StringCases["hello", x_..] 

Or do

ToExpression["StringCases[\"hello\", x_..]"] 

in the notebook. Both work correctly, x_.. is interpreted as a Repeated form of the pattern x_,

StringCases["hello", x_..] (* {"h", "e", "ll", "o"} *) 

Try it online!

In the notebook based front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error.

enter image description here

The code must be modified to

StringCases["hello", (x_)..] (* {"h", "e", "ll", "o"} *) 

Why is there a difference in behavior between the front end and direct kernel access (WolframScript)?parsers.

Repeated string pattern: difference between front end and WolframScript?

This code works fine in WolframScript: x_.. is interpreted as a Repeated form of the pattern x_,

StringCases["hello", x_..] (* {"h", "e", "ll", "o"} *) 

Try it online!

In the front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error. The code must be modified to

StringCases["hello", (x_)..] (* {"h", "e", "ll", "o"} *) 

Why is there a difference in behavior between the front end and direct kernel access (WolframScript)?

Repeated string pattern: difference between the FrontEnd and WolframScript?

This code works fine in a string based interface like WolframScript or Mathematica Kernel.

Run this through a string based interface

StringCases["hello", x_..] 

Or do

ToExpression["StringCases[\"hello\", x_..]"] 

in the notebook. Both work correctly, x_.. is interpreted as a Repeated form of the pattern x_,

Try it online!

In the notebook based front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error.

enter image description here

The code must be modified to

StringCases["hello", (x_)..] (* {"h", "e", "ll", "o"} *) 

Why is there a difference in behavior between the front end and kernel parsers.

Tweeted twitter.com/StackMma/status/1159252969956806658
deleted 53 characters in body; edited title
Source Link
Roman
  • 51.3k
  • 2
  • 62
  • 137

Repeated string pattern: has the lexer changeddifference between 11.3front end and 12WolframScript?

This code works fine in WolframScript V11.3.0: x_.. is interpreted as a Repeated form of the pattern x_,

StringCases["hello", s:x_..] (* {"h", "e", "ll", "o"} *) 

Try it online!Try it online!

In Mathematica 12.0.0the front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error. The code must be modified to

StringCases["hello", s:(x_)..] (* {"h", "e", "ll", "o"} *) 

What exactly has changed? I cannot findWhy is there a difference in the Precedence valuesbehavior between the versions. How can the lexer be spelunkedfront end and direct kernel access (WolframScript)?

Repeated string pattern: has the lexer changed between 11.3 and 12?

This code works fine in WolframScript V11.3.0: x_.. is interpreted as a Repeated form of the pattern x_,

StringCases["hello", s:x_..] (* {"h", "e", "ll", "o"} *) 

Try it online!

In Mathematica 12.0.0, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error. The code must be modified to

StringCases["hello", s:(x_)..] (* {"h", "e", "ll", "o"} *) 

What exactly has changed? I cannot find a difference in the Precedence values between the versions. How can the lexer be spelunked?

Repeated string pattern: difference between front end and WolframScript?

This code works fine in WolframScript: x_.. is interpreted as a Repeated form of the pattern x_,

StringCases["hello", x_..] (* {"h", "e", "ll", "o"} *) 

Try it online!

In the front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error. The code must be modified to

StringCases["hello", (x_)..] (* {"h", "e", "ll", "o"} *) 

Why is there a difference in behavior between the front end and direct kernel access (WolframScript)?

Source Link
Roman
  • 51.3k
  • 2
  • 62
  • 137
Loading