Lexical Errors:misspelling of keywords - lexical

In the dragon book it is mentioned that
"Lexical errors include misspelling of identifiers,keywords,or operators"
I am a bit confused how will a lexical analyzer find a misspelling of keyword wont it consider the misspelled keyword as an identifier?

Related

Sledgehammer within Locale

I am a happy user of Isabelle/Isar and Sledgehammer, but am just now trying to also use locales, as in my use case there are just overwhelming arguments for it.
I am using the Isabelle/December 2021 distribution, but most of the time when I am trying to use sledgehammer within a locale context, I will get a message like this:
"cvc4": Prover error:
exception TERM raised (line 457 of "~~/src/HOL/Tools/SMT/smt_translate.ML"): bad SMT term
It is the same message for other provers as well. Is this something that is a well-known problem? Without using locales I had such a problem only come up when my theory name was confused with some HOL theory name, and renaming my theory was a workaround. Is there something similar at play here? Is there an easy fix? Because I use sledgehammer a lot, so not being able to use it within a locale would be a severe blow against using locales.
For the sake of completeness, a summary of the discussion on the Isabelle mailing-list.
There is an issue in the translation from Isabelle to SMT Lib (the language for SMT solvers): lets inside lets are not translated correctly. This should be fixed in the next Isabelle release.
The work-around in the mean time is to avoid let inside let.

Data.Map - why is there `takeWhileAntitone` but no `takeWhile`?

I'm confused by Data.Map API. I'm looking for a simple way to find a range of keys of the map at log(n) cost. This is a basic concept known as "binary search", and maybe "bisecting".
I see this strange takeWhileAntitone function where I need to provide an "antitone" predicate function. It's the first time I encounter this concept.
After reading Wikipedia on the topic, this seems to be simply saying that there may be only one place where the function changes from True to False when applied to arguments in key order. This fits a requirement for a binary search.
Since the API is documented in a strange (to me) language, I wanted to ask here:
if my understanding is correct, and
is there a reason these functions aren't called bisect, binarySearch or similar?
Since the API is documented in a strange (to me) language, I wanted to ask here:
if my understanding is correct, and
Yes. takeWhileAntitone (and other similarly named variants in the library) is the function for doing binary search on keys. It's not named takeWhile because it does not work for any argument predicate, so if you're reviewing code, it serves as a reminder to check for that.
is there a reason these functions aren't called bisect, binarySearch or similar?
This name serves to distinguish variants takeWhileAntitone, dropWhileAntitone, spanAntitone that "do binary search" but with different final results.
takeWhile is a well-known name from Haskell's standard library (in Data.List).
In FP we like to distinguish the "what" from the "how". "binary search" is an algorithm ("how"). "take while" is also literally a "how", but its meaning is arguably more naturally connected to a "what" (the longest prefix of elements satisfying a predicate). In particular, the interpretation of "take while" as "longest prefix" doesn't rely on any assumption about the predicate.

Is there a BNF type grammar available for Purescript?

Is there a BNF type grammer description of the Purescript language?
It is hard to get a good handle on the language when the syntax is buried and scattered into various documentation of concepts and intent and so forth.
The closest thing to that would be the Parser.y file, in the purescript-cst sub-project.

Where are Default Parameters evaluated in Ada?

So we know Ada supports default parameters like so
procedure Example(param1 : Integer := 1);
But my question is, where the default parameter evaluated? In all languages where I'm familiar, the default parameter is merely inserted into calling code, which requires downstream recompilation if the default parameter is changed. Does Ada use this same approach?
I tried searching the ARM 2012, but couldn't find "default parameter" anywhere in the entire document. So then I checked 6.4 and 6.4.1 where it seems like the ARM calls the relevant part "default expressions". However "default expressions" links to 3.7 Discriminants. This might possibly be used to reduce the amount of times something is defined, however if it's common to two concepts they should do what programmers do and define it separately; this jump is confusing and seems like an error.
Note 59 reads:
The default_expression for a discriminant of a type is evaluated when an object of an unconstrained subtype of the type is created.
Well, that doesn't make any sense in regards to subroutine calls.
So again, when is a "default expression" for a subroutine actually evaluated?
You've been looking in the right place, but you must have missed the important part in RM 6.4 10/2:
10/2 For the execution of a subprogram call, the name or prefix of
the call is evaluated, and each parameter_association is evaluated
(see 6.4.1). If a default_expression is used, an implicit
parameter_association is assumed for this rule. These evaluations are
done in an arbitrary order.
I found it shortly after posting this question.
6.4.1 6.25/3 reads:
For a call, any default_expression evaluated as part of the call is considered part of the call.

Real World Haskell book: don't understand the example

In Chapter 3, There is an example called "MySecond.hs", what I really don't understand is code like this:
safeSecond :: [a] -> Maybe a
it always in the first line of file, and delete it causes no trouble. anyone could enlight me with what that means? I am but a newbie to any functional programming language.
It is the type annotation. If you don't write it Haskell will infer it.
In this case safeSecond is the name of something. The :: separates the name from the type. It takes a list of type a(a is a type variable this function will work on a list of any type.) -> is function application, and Maybe a is the return type.
Note that 'a' represents a single type so if you pass in a int list you must get a Maybe int out. That is to say all 'a's in the the type must agree.
Maybe is just a type that has two alternatives Just a or Nothing.
It's the type signature of the function. It's meant to show what the inputs and outputs of the function are supposed/expected to be. For most Haskell code the compiler can infer it if you don't specify it, but it is highly recommended to always specify it.
Aside from helping you remember what the function should actually do, it's also a nice way for others to get an idea about what the function does.
Besides that, it's also useful for debugging, for instance when the type of the function isn't what you expected it to be. If you have a type signature for that function, you would get an error at the definition site of the function, vs if you don't you'd get one at the call site. see Type Signatures and Why use type signatures
Also since you're reading RWH, Chapter 2 covers this.
This is a type annotation; it acts like a function declaration in C.
In Haskell, type declaration is usually not strictly necessary, as Haskell can usually infer a good type from correct code. However, it is generally a good idea to declare types for important values, because:
If your code is not correct, you tend get more useful error messages that way (otherwise the compiler can get confused trying to infer your types, and the resulting failure message may not be clearly related to the actual error). If you are getting obscure/verbose error messages, adding type annotation may improve them.
Especially as a beginner, declaring important types can make you less confused about what you're doing -- it forces you to clarify your thinking as you write the program.
As others have mentioned, type annotation acts as active documentation, making other people less confused about your code. As usual, "other people" may be you, a few months down the road.

Resources