What does (*s mean in OCaml? - comments

I'm looking at an OCaml source file that begins like this
(*s Implementation of n-ary trees. (Some code is borrowed from the OCaml
standard library, which is copyright 1996 INRIA.) *)
What does (*s mean? I thought the s might be a typo, but it appears in several files, so it must be deliberate.

(*s is apparently used by ocamlweb, a literate programming tool for OCaml (see https://www.lri.fr/~filliatr/ocamlweb/ocamlweb-1.38-man.html).

There is no such thing in ocaml.
Everything inside (* *) are comments.
May be it must be a convention used by them.

Related

Functions missing in repl.it Scheme?

Using scheme in repl.it, several functions don’t appear to exist, such as modulo, remainder, inc. Am I missing something? Do I need to import some library or anything? I know there are various permutations of scheme but as far as I can tell these are actual base scheme functions.
At the time of writing repl.it uses BiwaScheme v0.6.4 under the hood, which is quite incomplete (the most recent version is v0.7.0, by the way.) It does not fully implement a Revised Report for the Scheme language, because procedures such as modulo or remainder are a standard part of the language. According to their implementation status page:
BiwaScheme has most features of R6RS Base library. The biggest features not implemented are errors and syntax-rules (you can use define-macro instead).
In particular, the arithmetic section is listed as "not yet" conforming to the standard. There isn't much you can do about it, apart from switching to a standard-conformant interpreter. May I suggest Racket?

Is there a prolog language grammar/spec?

Is there a prolog language grammar, or something close to it that is generally used as a reference? I am using SWI-prolog, so one for that flavor would be nice to have, otherwise a general prolog language grammar/specification works as well.
Since 1995, there is an ISO/IEC standard for Prolog: ISO/IEC 13211-1:1995. It also contains a grammar defining Prolog's syntax which consists of two levels:
Token level: (6.4 Tokens, 6.5 Processor character set)
These are defined by regular expressions and using the longest input match/eager consumer rule/greedy match/maximal munch like many languages of that era. In the words of the standard (6.4):A token shall not be followed by characters such thatconcatenating the characters of the token with these characters forms a valid token as specified by the above syntax.NOTES1 This is the eager consumer rule: 123.e defines the tokens123 . e. A layout text is sometimes necessary toseparate two tokens.
This way of defining tokens is typical for programming languages originating in the 1970s.
The token level is of particular importance to Prolog's syntax, because term, or read term is first defined as a sequence of tokens:
term (* 6.4 *)
= { token (* 6.4 *) } ;
read term (* 6.4 *)
= term (* 6.4 *) , end (* 6.4 *) ;
Many tokens contain an optional layout text sequence in the beginning. But never at the end. Also note that to determine the end (that is the finishing period), a lookahead to the next character is required. In a tokenizer written in Prolog, this would be realized with peek_char/1.
Only after identifying a term on this level, the actual grammar comes into play. See the 8.14.1.1 Description of read_term/3. Of course, an implementation might do it differently, as long as it behaves "as if".
Syntax level: (6.2 Prolog text and data, 6.3 Terms)
These definitions rely on the full context-free grammar formalism plus a few context sensitive constraints.
Conformance
As to conformance of implementations,
see this table. SWI always differed in many idiosyncratic ways: both on the token level and on the syntax level. Even operator syntax is (for certain cases) incompatible with other systems and the standard. That is, certain terms are read differently. Since SWI7, SWI now differs even for canonical syntax. Try writeq('.'(1,[])). This should yield [1], but SWI7 produces some error.
For conforming implementations see sicstus-prolog (version 4.3) and gnu-prolog.
For SWI-Prolog in particular, things are a bit "complicated". It has never strictly conformed to ISO, and the current development version (SWI-Prolog 7 and beyond) has departed even further from ISO compliance. The development version is at the moment the only "actively" maintained version, meaning that soon you might expect bugs not to be removed from SWI-Prolog 6.
As for reference, you will have to read the manual and hope to figure out what is right and what is not. The information is all there, even if it is not super neatly organized.
This is where you might start:
http://www.swi-prolog.org/pldoc/man?section=syntax
The books recommended:
http://www.swi-prolog.org/pldoc/man?section=intro
are actually something that you can't completely circumvent, unfortunately (I would be glad if someone proves me wrong). Get at least one of the three listed there. Sterling & Shapiro, 1986 is for example a good starting point. The online tutorial at http://www.learnprolognow.org/ is also quite good.
Something else: in "The Craft of Prolog" by Richard O'Keefe you can find the full implementation of a Prolog tokenizer, written in Prolog (10.7, pp 337-354). I don't know if this would serve your purpose.
And some advice: make the effort to install the current development version if you are going to use SWI-Prolog. It is fairly easy on Linux (no idea how it goes on MacOS in practice, but I doubt it is more complicated).
At least, there is ISO standard (see its creator page).

Is the Prova implemented with a Prolog compiler or Prolog interpreter?

I am looking at the Java-written Prolog system, Prova.
https://prova.ws/
But it is not clear about its implementation, a Prolog compiler or Prolog interpreter? I read the manual, but did not found an answer.
There are some rumors that Prova is based on Mandarax. The newest
version seem to be heading in the same direction as SWI-Prolog 7,
i.e. it supports dicts and a dot notation. See also here:
http://prova.ws/confluence/display/REWRITEDEV/Prova+maps+for+defining+slotted+terms
The original Mandarax seems to have been an interpreter, and
in the user manual of Prova we find one sentence that self
declares it as a Prolog interpreter, but no hint for compilation.
But there seems to be a newer version of Mandarax (1.1.0) which was
some kind of compiler, but maybe Prova was already branched out
before the compiler arrived, and its still an interpeter.
So although it self declares as a Prolog interpreter, it is most
likely not an ISO Prolog systems, since for example op/3 is missing.
I guess it uses aa tokenizer with some hard wired operators and a
parser with some hard wired operator expressions. (*)
It might nevertheless offer some goodies, but judging from the
documentation and binary size, they might not be many. Which
is possibly compensated by the ability to directly embed Java
calls by the dot notation:
http://prova.ws/confluence/display/REWRITEDEV/Calling+Java+from+Prova+rulebases
Bye
(*)
The Prova syntax goes even that far, that it requires the end-user
to write fail() instead of fail. A syntax variant that is also
found in the new SWI-Prolog 7, although not with the same drastic
effect on the end-user that he/she would be not anymore allowed to use
atoms as goals.

Trying to understand Wirth's Pascal pl/0 compiler code

Is there a simple explanation of Wirth's source code or even a version with a little more commenting so that I can figure out how it works?
Wirths pl/0 compiler is here: http://www.moorecad.com/standardpascal/plzero.pas
My main goal is to modify it to work with integer arrays similarly to Oberon but to touch the code as little as possible
Oberon referenced here: http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf
The code is described in detail in Wirth's book, Algorithms + Data Structures = Programs. I'm looking at the 1976 edition, which contains about 70 pages about the program.
As far as I can tell, the 1976 version of the book is not online, but he later ported the code to Modula-2 and then Oberon. The Oberon edition is available as a free PDF, but the PL/0 chapter was removed and expanded into a second book (also free online), Compiler Construction.
This expanded book uses a more robust language called Oberon-0, which includes arrays, records, types, etc. He discusses in detail how to implement each of these things.
The entire compiler is different, since it's written in Oberon and targets a different machine, but all of Wirth's compilers share the same basic structure, so you should be able to map ideas between them.
Alternatively, he also wrote another expanded compiler in pascal (the "p4" reference implementation for ISO pascal. That compiler has been extensively studied and documented in the book Pascal Implementation, now transformed into a nice website with hypertext cross references to the source.
Finally, there is also a python port of the PL/0 compiler by Samuel G Williams. My fork of his PL/0 Languages Tools includes a couple additional back-ends, as well as a copy of Wirth's original code (the program you linked), modified slightly to run under Free Pascal.

When does "1..10" make sense?

I have a vague memory of a programming language where 1..10 meant "the range 1 inclusive to 10 exclusive", similar to python's range(1, 10), but I haven't the foggiest which, and this doesn't particularly lend itself to searches. Any help?
If the answer's "python", please forgive me. I know very little python.
Pascal supports that syntax. You can actually use this as a type, and I believe it's also used in specifying array bounds. (I'm not sure how much of this is standard Pascal and how much is Turbo Pascal extensions.)
Haskell does it.
It is Perl, called the "Range Operator"
http://www.cs.cf.ac.uk/Dave/PERL/node38.html
Groovy uses this syntax, too.
http://groovy.codehaus.org/Collections
F#, they are called Sequence Expressions
http://msdn.microsoft.com/en-us/library/dd233209.aspx (select the F# examples to see the code)
Ruby!
Since the OP already got the answer they were looking for, and this has kind of become a list of languages that use 1..n syntax, I'll add one more.
Maple
The wiki page shows a good example
myfac := n -> product( i, i=1..n );
Note however that this is 1 to 10 inclusive
Ruby has VERY similar syntax...
You can read more here:
http://www.ruby-doc.org/core/classes/Range.html
If it's a vague and distant memory, then I'd guess that Pascal or Delphi is the most likely candidate for the language you're thinking of.
It's most commonly used in Pascal in a case statement. See here for example syntax: http://en.wikipedia.org/wiki/Switch_statement#Pascal
It could also be any of a number of other languages that use this syntax, but without knowing a bit more about your programming history, my guess would still be Pascal / Delphi.

Resources