Visualizzazione post con etichetta storia. Mostra tutti i post
Visualizzazione post con etichetta storia. Mostra tutti i post

10 settembre, 2020

REPL un'idea che ha cambiato l'informatica

 


Una cosa che avrei voluto fare da piccolo era affiancare il Lisp al Fortran; cosa impossibile, anzi impensabile, ancora adesso è pericoloso nominarlo. Ma sono vecchio e chissene!

Una cosa che in qualche misura --mica ne sono addicto nèh!-- è la storia, non universale ma quella limitata all'informatica, hardware e software; non tutto, solo quello con cui ho avuto (o avrei voluto) a che fare.

L'altro giorno mi capita che --questo lo racconto dopo, prima l'ambiento.

Non sono interessi solo miei, anzi! Per esempio su Twitter Duncan McGregor rilancia un tweet di tanto tempo fa, questo.

Il link originario non c'è più ma seguendo il thread si arriva a una meraviglia, il PDF di The LISP Implementation for the PDP-1 Computer di L. Peter Deutsch e Edmund C. Berkley, roba di DEC, marzo 1964, troppo presto allora ero alle medie.

Nota: L Peter Deutsch rockz! 💥 Davvero.

Bellissimo, c'è tutto, chiaro, conciso, bastano una quarantina di pagine. Non parlo del linguaggio (anche se ...) ma della novità del cap. 6. Input and Output: l'interattività.

È sempre  Oubiwann  Duncan che lancia questo 3D (si capisce che sta per thread?) che --ve lo dicevo che non è una fissa solo mia-- "'ve had a heck of a time determining when the first true LISP REPL was implemented"

Salto ma uh! questo lo ricordo, cioè non lui ma un rifacimento in Basic su Prime, fine anni '70, questo


io l'avevo anche tradotto in italiano; siccome il DB (un semplice file di testo) cresceva con le risposte dopo un po' era tutto in italiano. No, non c'era il web, non l'ho diffuso, chissà se c'è ancora qualche nastro... No, il Prime non c'è più, come neanche DEC (Digital Equipment Corporation).

OK, sto divagando ma tanti dei vecchi la REPL l'hanno conosciuta e usata con il Basic, probabilmente il GW-Basic se su IBM (o compatibile) o qualche altra implementazione.

Roba di fine anni '60. Non solo Basic, ovviamente; per esempio bc (1975) e prima ancora il suo antenato dc ("dc is the oldest surviving Unix language" dice la Wiki).

Quelli seri (o solo i vecchi?) allora non usavano il PC, non usavano linguaggi interpretati (cioè, a dirla tutta, usavano il Fortran). Non immaginavano che il futuro sarebbe stato quello che poi è stato. E i linguaggi interpretati avrebbero vinto, confinando i compilati in alcuni settori, non che non siano fondamentali ma è comunque una riserva. E oggi è normale, per esempio Python:

$ python3 -q
>>> 3 + 5
8
>>> a = 8 + (3 + 4) * 5 - 1
>>> a
42
>>>
$

o Node.js, come dire JavaScript:

$ node
> 3 + 5
8
> a = 8 + (3 + 4) * 5 - 1
42
> $

o Racket, evoluzione di Scheme, evoluzione del Lisp:

$ racket
Welcome to Racket v7.8.
> (+ 3 5)
8
> (define a (- (+ 8 (* (+ 3 4) 5)) 1))
> a
42
> ^D
$

Anzi, no: le REPLs ci sono ma si usano ambienti inegrati, IDEs molto più user friendly (io no, ma solo perché sono vecchio).

L'altro giorno salta fuori che Bash, la solita shell, la REPL... Si può fare, ecco un template, fa poco,  upcasizza  maiuscolizza, dipende tutto dall'eval.

n=0
while read -ep "$n > " line; do
    if [[ $line == "q!" ]]; then
        echo 'bye!'
        exit 0
    fi
    echo ${line^^}
    (( n++ ))
done

$ bash repl.sh
0 > esempio di REPL
ESEMPIO DI REPL
1 > fa poco, è un template
FA POCO, È UN TEMPLATE
2 > (si esce come nel vi)
(SI ESCE COME NEL VI)
3 > q!
bye!
$

Idea 💡, forse:

$ eval r=$(( 5 + 4 ))
$ echo $r
9
$

No, meglio Excel (o bc, per me).
🔴🔵

31 agosto, 2019

Notarelle storiche sul Lisp - 8


Continuo da qui l'esplorazione dagli inizi del Lisp. Continuo con History of Lisp di John McCarthy, sono arrivato a From LISP 1 to LISP 1.5, qui a p.10.

Salta fuori molto presto che ci sono cose da migliorare o cambiare, troppo difficile (per me) farne il riassunto. C'è anche una confessione divertente di JMC, inizialmente pensa che il lexical scope sia un bug e che Steve Russell correggerà presto. Sì fatto, anche per Algol 60, bravo Steve!

eval è ottimo come interprete ma il compilatore deve ancora arrivare: [t]he first attempt at a compiler was made by Robert Brayton, but was unsuccessful. The first successful LISP compiler was programmed by Timothy Hart and Michael Levin. It was written in LISP and was claimed to be the first compiler written in the language to be compiled.

Quelli che hanno fatto l'impresa: [m]any people participated in the initial development of LISP, and I haven’t been able to remember all their contributions and must settle, at this writing, for a list of names. I can remember Paul Abrahams, Robert Brayton, Daniel Edwards, Patrick Fischer, Phyllis Fox, Saul Goldberg, Timothy Hart, Louis Hodes, Michael Levin, David Luckham, Klim Maling, Marvin Minsky, David Park, Nathaniel Rochester of IBM, and Steve Russell.

Poi si passa Beyond LISP 1.5. As a programming language LISP had many limitations. Some of the most evident in the early 1960s were ultra-slow numerical computation, inability to represent objects by blocks of registers and garbage collect the blocks, and lack of a good system for input-output of symbolic expressions in conventional notations. All these problems and others were to be fixed in LISP 2. In the meantime, we had to settle for LISP 1.5 developed at M.I.T. which corrected only the most glaring deficiencies.

The LISP 2 project was a collaboration of Systems Development Corporation and Information International Inc., and was initially planned for the Q32 computer, which was built by IBM for military purposes and which had a 48 bit word and 18 bit addresses, i.e., it was better than the IBM 7090 for an ambitious project. Unfortunately, the Q32 at SDC was never equipped with more than 48K words of this memory. When it became clear that the Q32 had too little memory, it was decided to develop the language for the IBM 360/67 and the Digital Equipment PDP-6. [...] The
project proved more expensive than expected, the collaboration proved more difficult than expected, and so LISP 2 was dropped
[...] this was regrettable, because much more money has since been spent to develop LISPs with fewer features. However, it was not then known that the dominant machine for AI research would be the PDP-10, a successor of the PDP-6.

The existence of an interpreter and the absence of declarations makes it particularly natural to use LISP in a time-sharing environment. It is convenient to define functions, test them, and re-edit them without ever leaving the LISP interpreter. A demonstration of LISP in a prototype time-sharing environment on the IBM 704 was made in 1960 (or 1961). (Nel corso di una dimostrazione importante partì GC scrivendo (at ten characters per second) “THE GARBAGE COLLECTOR HAS BEEN CALLED. SOME INTER-
ESTING STATISTICS ARE AS FOLLOWS:
” and on and on and on. The garbage collector was quite new at the time, we were rather proud of it and curious about it, and our normal output was on a line printer, so it printed a full page every time it was called giving how many words were marked and how many were collected and the size of list space, etc. During a previous rehearsal, the garbage collector hadn’t been called, but we had not refreshed the LISP core image, so we ran out of free storage during the demonstration.
Nothing had ever been said about a garbage collector, and I could only imagine the reaction of the audience. We were already behind time on a tight schedule, it was clear that typing out the garbage collector message would take all the remaining time allocated to the demonstration, and both the lecturer and the audience were incapacitated by laughter. I think some of them thought we were victims of a practical joker).


L. Peter Deutsch implemented the first interactive LISP on the PDP-1 computer in 1963, but the PDP-1 had too small a memory for serious symbolic computation.

Perso: quando ho iniziato a pasticciare con il Lisp (illo tempore) l'interprete interattivo, quello che oggi si chiama REPL, era quello che mi affascinava; vero che c'era anche con il Basic ma frequentavo molto meno.

The most important implementations of LISP proved to be those for the PDP-6 computer and its successor the PDP-10 made by the Digital Equipment Corporation of Maynard, Massachusetts. In fact, the half word instructions and the stack instructions of these machines were developed with LISP’s requirements in mind. The early development of LISP at M.I.T. for this line of machines and its subsequent development of INTERLISP (nee BBN LISP) and MACLISP also contributed to making these machines the machines of choice for artificial intelligence research. The IBM 704 LISP was extended to the IBM 7090 and later led to LISPs for the IBM 360 and 370.

Sempre sul personale: i DEC, prima PDP e poi VAX, erano le macchine sognate da tutti (tranne i commerciali); purtoppo gli utenti sono poi risultati rivali di Unix, a parte i PCisti.

[T]he LISP 1.5 Programmer’s Manual by McCarthy, Levin, et. al. in 1962 was published by M.I.T. Press. After the publication of (McCarthy and Levin 1962), many LISP implementations were made for numerous computers. However, in contrast to the situation with most widely used programming languages, no organization has ever attempted to propagate LISP, and there has never been an attempt at agreeing on a standardization.

JMC conclude con LISP is now the second oldest programming language in present widespread use (after FORTRAN and not counting APT, which isn’t used for programming per se). It owes its longevity to two facts. First, its core occupies some kind of local optimum in the space of programming languages given that static friction discourages purely notational changes. Recursive use of conditional expressions, representation of symbolic information externally by lists and internally by list structure, and representation of program in the same way will probably have a very long life. Second, LISP still has operational features unmatched by other language that make it a convenient vehicle for higher level systems for symbolic computation and for artificial intelligence. These include its run-time system that give good access to the features of the host machine and its operating system, its list structure internal language that makes it a good target for compiling from yet higher level languages, its compatibility with systems that produce binary or assembly level program, and the availability of its interpreter as a command language for driving other programs.
LISP will become obsolete when someone makes a more comprehensive language that dominates LISP practically and also gives a clear mathematical semantics to a more comprehensive set of features.


Ancora vero oggi quando il documento ha ben 40 anni; c'è stata un'evoluzione del LISP che ha generato discendenti, p.es. Scheme e Racket. Ha influenzato altri linguaggi, ne sono nati tanti altri, anche concorrenti del LISP, p.es. o funzionali. Continua --secondo qualcuno-- a esserci anche il FORTRAN, anche lui presente nei periodici RedMonk Programming Language Rankings in buona posizione.

OK, pausa ma continuo, siamo ancora agli inizi.
🔴

26 luglio, 2019

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

Una cosa che avevo già visto ma di corsa (manca sempre il tempo) e c'è voluto il suggerimento di Mariano Tomatis, the Wonder Injector, a farmelo apprezzate come si deve.

Tutto qui, 95 secondi densi; da rivedere più volte. Notare che lo schermo è attuale ma il 'puter è quello che dice, il Commodore 64.

Il libro cui fa riferimento è distante un hoogle, qui: 10 PRINT CHR$(205.5+RND(1)); : GOTO 10. E in questa stessa pagina c'è il link al PDF liberamente scaricabile, lo faccio subito-subito.

Il volume fa parte di una serie dedicata al software: Software is deeply woven into contemporary life—economically, culturally, creatively, politically—in manners both obvious and nearly invisible.

This book returns to a moment, the early 1980s, by focusing on a
single line of code, a BASIC program that reads simply:

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

One line of code, set to repeat endlessly, which will run until interrupted.


Segue una descrizione dettagliata che salto ma ne approfitto per qualche considerazione strettamente personale. Io allora ero già indaffarato nel lavoro, su Prime, minicomputer simile al più noto PDP-11. Per i giovani una precisazione: "mini" significa grosso come un armadio, era inteso relativo ai mainframes; non dico delle caratteristiche tecniche perché non sarei creduto. E sì, in Fortran, c'era solo quello (praticamente).

La rivoluzione dei personal come il Commodore 64 e gli altri raccontati nel libro me la sono persa tutta fino all'arrivo del PC IBM (e compatibili, di marca e assemblati (si capisce ancora questo termine?)).

Ripensandoci dopo è stato come quella volta dell'asteroide sui dinosauri. Cambiato tutto anche il linguaggio. Il nuovo era --grosso "ohh!" per me-- il BASIC.

Salto, si può (deve) leggere nel book originale, molto dettagliato. Salto anche tutto quanto detto sui labirinti (dei due tipi, in italiano c'è quella distinzione?) ma apprezzo la figura 20.2 a p.42 raffigurante [i]nformation theory pioneer Claude Shannon pictured ca. 1950 with his mechanical mouse Theseus and its magnetic metal maze. Bellissima.

A p.52 si parla di port, adattamento di un programma a un sistema differente, cosa che allora era un'attività normale per i i mini, ognuno aveva un OS proprio e anche i linguaggi di programmazione dovevano essere adattati. Per esempio con il Fortran le unità (canali?) di I/O non erano predefinite; e le connessioni venivano stabilite all'esterno del programma --roba che oggi risulta difficilmente comprensibile.

Ma il port di cui tratta il nostro caso è più generale, e affrontato per le macchine comparabili al Commodore 64. Per Apple "Applesoft BASIC is one of two standard BASIC implementations for the Apple II; Applesoft is the one that supports floating point math and seems very similar to Commodore 64 BASIC. The Apple II family of computers was of the same era and uses the same processor as did the Commodore 64, the MOS 6502. Applesoft BASIC, like Commodore 64 BASIC, was written by Microsoft and based on its 6502 BASIC, a version [...] that derives from Microsoft’s Altair BASIC. The Apple II computers and the Commodore 64 were really quite alike, almost as if they were siblings separated by corporate circumstance". Ma i caratteri da stampare sono diversi, non c'è l'estensione all'ASCII oltre 127 del PETSCII. E "[a]lthough the “/” and “\” characters on Apple II computers are exactly diagonal, they do not span the entire square that bounds a character". c'era anche "the TRS-80 Color Computer (or “CoCo”), sold through Radio Shack" con ancora una diversa variante, dovuta alla funzione RND.

Esistono ovviamente versioni nei linguaggi contemporanei, tre sono riportate nel testo ma più interessanti quelle disponibili nel Web.

Io avevo già scritto una versione Python che poi ho scoperto versioni molto simili online (mi hanno pre-copiato!). E al posto di "/\" (quest'ultimo da escapare) si può/deve usare "\u2571\u2572".
Ma meglio partire da qui, qui e qui.

Salto a p.76 dove si parla di Joseph-Marie Jacquard e il suo telaio programmabile, antenato di nastri e schede perforate, vedi figura 30.9 a p.77 per un esempio esagerato; le schede IBM per il Fortran (vecchie e in disuso quando ho cominciato a lavorare) erano molto più semplici. Ma questo non riguarda il Basic, anzi ecco qui (io lo scopro adesso) il vero aspetto rivoluzionario del Basic.

I computers (commodore 64, Apple I e II e simili) sono descritti per quanto riguarda le caratteristiche dell'output in "The Computer Screen", p.85. A me interessa un altro aspetto: [e]arly interaction with computers happened largely on paper: on paper tape, on punch cards, and on print terminals and teletypewriters, with their scroll-like supplies of continuous paper for printing output and input both [...]. The standard output devices for computers through much of the 1970s were print terminals and teletypes. Output was not typically produced on pages of the sort that come from today’s laser printers, but on scrolls of standard or thermal paper. The form factor for such output was not a standard 81/2 × 11-inch page, but an essentially endless scroll that was typically 80 columns wide.

Adesso devo tenermi forte, ci arrivo con 40 anni di ritardo:

Teletypes were used to present the results of the first BASIC programs written at Dartmouth in the 1960s, and they were the typical means of interacting with important early programs such as Eliza and Adventure. With such a system for output, there was no need for an automated means of saving and viewing the “scrollback” --a user could actually pick up the scroll of output and look at it. Of course, this sort of output device meant that animation and other effects specific to video were impossible.
Why are typed line numbers required at all in a BASIC program? Programs written today in C, Perl, Python, Ruby, and other languages don’t use line numbers as a language construct: they aren’t necessary in BASIC either, as demonstrated by QBasic and Visual Basic, which don’t make use of them. If one wants a program to branch to a particular statement, the language can simply allow a label to be attached to the target line instead of a line number. Where line numbers particularly helped was in the act of editing a program, particularly when using a line editor or without access to a scrolling full-screen editor. The Commodore 64 does allow limited screen editing when programming in BASIC: the arrow keys can be used to move the cursor to any visible line, that line can be edited, and the new version of the line can be saved by pressing RETURN. This is a better editing capability than comes standard on the Apple II, but there is still no scrollback (no ability to go back past the current beginning of the screen) in BASIC on the Commodore 64. Line numbers provide a convenient way to get back to an earlier part of the program and to list a particular line or range of lines. Typing a line number by itself will delete the corresponding line, if one exists in memory. The interactive editing abilities that were based on line numbers were well represented even in very early versions of BASIC, including the first version of the BASIC that ran on the Dartmouth Time-Sharing System. Line numbers thus represent not just an organizational scheme, but also an interactive affordance developed in a particular context.
Ecco: la quantità di memoria estremamente ridotta, la mancanza di un editor e un OS estremamente ridotto tutti motivi che portano alla soluzione (ottima, lo ammetto del BASIC). Anche se --no questo lo dico dopo; probabilmente; forse.

Ovviamente il libro contiene molte altre cose, tante, troppe anche per solo elencarle in questo post. Solo un'eccezione: l'Atari 2600, non sapevo delle sue particolarità; un suo successore, l'ST diventò l'utensile indispensabile per compositori musicali computerizzati --OK, sono OT con ricordi perso.

Gli autori tutti rockzs! 💥 anche se sono solo Basic, si parla dei personal di quell'era e allora è giusto così.

Però --torno a dirmi-- altrove si faceva in modo diverso, completamente. E --ma sono solo io che mi sono perso quell'avventura-- il Basic e i programmatori Basic come dice EWD the teaching of BASIC should be rated as a criminal offence: it mutilates the mind beyond recovery.

Peraltro negli stessi anni diceva: FORTRAN, 'the infantile disorder', by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expensive to use. E: In the good old days physicists repeated each other's experiments, just to be sure. Today they stick to FORTRAN, so that they can share each other's programs, bugs included. Qui si sbagliava.
🔴

23 luglio, 2019

Notarelle storiche sul Lisp - 6


Continuo da qui l'esplorazione dagli inizi del Lisp.

Continuo l'esame di Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, sono giunto a Flowcharts and Recursion.

Since both the usual form of computer program and recursive function definitions are universal computationally, it is interesting to display the relation between them. The translation of recursive symbolic functions into computer programs was the subject of the rest of this report. In this section we show how to go the other way, at least in principle.

Semplifico al massimo, un programma può essere rappresentato in un flowchart come questo:


Given a flowchart with a single entrance and a single exit, it is easy to write down the recursive function that gives the transformation of the state vector from entrance to exit in terms of the corresponding functions for the computation blocks and the predicates of the branch.

Con qualche (non troppo ovvia manipolazione) [w]e then write


e quindi


, sto svicolando 🤪 JMC conclude con ringraziamenti e bibliografia, per me è arrivato il momento di esaminare un altro documento.
🔴

19 luglio, 2019

Notarelle storiche sul Lisp - 5


Continuo da qui l'esplorazione dagli inizi del Lisp.

Continuo l'esame di Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, sono giunto a Another Formalism for Functions of Symbolic Expressions.

Considerazioni sulle espressioni simboliche, teoriche, non so se ci arrivo a capire per bene, comunque ecco:

There are a number of ways of defining functions of symbolic expressions which are quite similar to the system we have adopted. Each of them involves three basic functions, conditional expressions, and recursive function definitions, but the class of expressions corresponding to S-expressions is different, and so are the precise definitions of the functions. We shall describe one of these variants called linear LISP.

The L-expressions are defined as follows:
[...]

Non riporto ma volendo è là. Mi sembra tutto normale car viene chiamato first e cdr rest. C'è nil qui chiamato Λ.

The advantage of linear LISP is that no characters are given special roles, as are parentheses, dots, and commas in LISP. This permits computations with all expressions that can be written linearly. The disadvantage of linear LISP is that the extraction of subexpressions is a fairly involved, rather than an elementary, operation. It is not hard to write, in linear LISP, functions that correspond to the basic functions of LISP, so that, mathematically, linear LISP includes LISP. This turns out to be the most convenient way of programming, in linear LISP, the more complicated manipulations. However, if the functions are to be represented by computer routines, LISP is essentially faster.

Uh! capito: linear LISP rende macchinoso calcolare funzioni entro funzioni, quello che si fa normalmente.

Pausa, non per pigrizia ma voglio prenderlo a piccole dosi; e poi in questi giorni fa caldo, troppo.
🔴

15 luglio, 2019

Notarelle storiche sul Lisp - 4


Continuo da qui l'esplorazione dagli inizi del Lisp.

Continuo l'esame di Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, sono giunto a Recursive Functions of Symbolic Expressions.

Il capitolo The LISP Programming System ci dice The LISP programming system is a system for using the IBM 704 computer to compute with symbolic information in the form of S-expressions. It has been or will be used for the following purposes:
  1. Writing a compiler to compile LISP programs into machine language.
  2. Writing a program to check proofs in a class of formal logical systems.
  3. Writing programs for formal differentiation and integration.
  4. Writing programs to realize various algorithms for generating proofs in predicate calculus.
  5. Making certain engineering calculations whose results are formulas rather than numbers.
  6. Programming the Advice Taker system.
Uh! cose difficili (un compilatore --a quei tempi!--, calcolo integrale, elaborazioni risultanti in formule invece di numeri, l'Advice Taker; tutta roba che con il Fortran nemmeno a pensarci.

Ci sono inoltre facilities for using S-functions in programs written as sequences of statements along the lines of FORTRAN or ALGOL.

E la via è quella che sarebbe stata quella vincente: [t]he basis of the system is a way of writing computer programs to evaluate S-functions.

La descrizione che segue, molto tecnica, è quella della rappresentazione delle S-expressions via liste strutturate:


L'ultima struttura (ciclo) non è permessa.

Status of the LISP Programming System (February 1960). A variant of the function apply described in section 5f has been translated into a program APPLY for the IBM 704. Since this routine can compute values of S-functions given their descriptions as S-expressions and their arguments, it serves as an interpreter for the LISP programming language.

Poi, cosa vecchia ma siamo agli inizi (io ho 8 anni): [a] "program feature" allows programs containing assignment and go to statements in the style of ALGOL.

E [c]omputation with floating point numbers is possible in the system, but this is inefficient.

E [a] programmer's manual is being prepared. The LISP programming system is appropriate for computations where the data can conveniently be represented as symbolic expressions allowing expressions of the same kind as subexpressions. A version of the system for the IBM 709 is being prepared.

Il computer di riferimento è l'IBM 704, la Wiki ci dice tutto, come al solito.
🔴

09 luglio, 2019

Notarelle storiche sul Lisp - 3


Continuo da qui l'esplorazione dagli inizi del Lisp.

Continuo l'esame di Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, sono giunto a Recursive Functions of Symbolic Expressions.

We shall first define a class of symbolic expressions in terms of ordered pairs and lists. Then we shall define five elementary functions and predicates, and build from them by composition, conditional expressions, and recursive definitions an extensive class of functions [...] We shall then show how these functions themselves can be expressed as symbolic expressions, and we shall define a universal function °°apply that allows us to compute from the expression for a given function its value for given arguments. Finally, we shall define some functions with functions as arguments and give some useful examples.

le S-expressions (S sta per simboliche) sono formate usando i caratteri speciali ., ( e ) e un set infinito di simboli atomici distinti. Cose note a parte che le lettere devono essere maiuscole e sono ammessi gli spazi perché gli elementi delle liste sono separati da virgole, cosa che sarà presto rivista.

S-expressions are then defined as follows:
  1. Atomic symbols are S-expressions.
  2. If e1 and e2 are S-expressions, so is (e1 . e2).
Examples of S-expressions are
  • AB
  • (A . B)
  • ((AB . C) . D)

An S-expression is then simply an ordered pair, the terms of which may be atomic symbols or simpler S-expressions. We can can represent a list of arbitrary length in terms of S-expressions as follows. The list (m1, m2, ..., mn) is represented by the S-expression (m1 . (m2 . ( ... (mn .NIL) ... ))) dove NIL è il simbolo usato per terminare le liste.

Functions of S-expressions and the Expressions That Represent Them. We now define a class of functions of S-expressions. Le funzioni sono scritte nel modo convenzionale (M-expressions) usando lettere minuscole.

Vengono definite car, atom, eq, car, cdr, cons. E poi le [r]ecursive S-functions. We get a much larger class of functions (in fact, all computable functions) when we allow ourselves to form new functions of S-expressions by conditional expressions and recursive definition.

Poi subst, equal, append, among [?], pair, assoc.

Representation of S-Functions by S-Expressions. S-functions have been described by M-expressions. We now give a rule for translating M-expressions into S-expressions, in order to be able to use S-functions for making certain computations with S-functions and for answering certain questions about S-functions. Questa descrizione è diversa da quella che si sarebbe usata in seguito, salto.

The Universal S-Function apply. Uh! qui descrizione lunga, salto, da leggere nell'originale.

Inoltre eval, quote, e label.

Functions with Functions as Arguments. There are a number of useful functions some of whose arguments are functions. They are especially useful in defining other functions. One such function is maplist, simile a map di Racket. Esempi d'uso plus e times.

È difficile per me riassumere, anche perché sono troppo legato dal sapere dove si va a parare. Il post continua a non piacermi ma l'ho già rimaneggiato troppe volte; sono solo considerazioni personali, non leggetelo.
🔴

05 luglio, 2019

Notarelle storiche sul Lisp - 2


Continuo da quì l'esplorazione dgli inizi del Lisp

Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I è il paper che introduce il Lisp, ci racconta tutto quello che serve per iniziare. Siccome c'è tutto Part II non ci sarà. Il PDF non è perfetto, forse meglio usare la versione HTML.

A programming system called LISP (for LISt Processor) has been developed for the IBM 704 computer by the Artificial Intelligence group at M.I.T. The system was designed to facilitate experiments with a proposed system called the Advice Taker, whereby a machine could be instructed to handle declarative as well as imperative sentences and could exhibit "common sense" in carrying out its instructions. The original proposal  for the Advice Taker was made in November 1958. The main requirement was a programming system for manipulating expressions representing formalized declarative and imperative sentences so that the Advice Taker system could make deductions.

In the course of its development the Lisp system went through several stages of simplification and eventually came to be based on a scheme for representing the partial recursive functions of a certain class of symbolic expressions. This representation is independent of the IBM 704 computer, or of any other electronic computer, and it now seems expedient to expound the system by starting with the class of expressions called S-expressions and the functions called S-functions.

Qui (e siamo appena nel secondo paragrafo ci sono due grosse notizie, il Lisp non sarà legato al computer attualmente disponibile e usato per lo sviluppo e sarà basato su funzioni ricorsive. Ecco siamo ai tempi in cui domina il Fortran (ancora in non standardizzato, roba interna IBM e Academia, anche se c'è già Algol, tentativamente).

Una cosa che il Fortran vieta espressamente è la ricorsività, sia diretta che indiretta. Se ricordo bene la ragione era dovuta alla scarsità di memoria disponibile, ma niente panico, trasformi la serie di chiamate ricorsive in un ciclo (non so se è sempre possibile, dovrei pensarci su o fare un salto a quell'epoca con la macchina del tempo).

In this article, we first describe a formalism for defining functions recursively. We believe this formalism has advantages both as a programming language and as vehicle for developing a theory of computation. Next, we describe S-expressions and S-functions, give some examples, and then describe the universal S-function apply which plays the theoretical role of a universal Turing machine and the practical role of an interpreter.

L'informatica, al tempo, è giovane e si devono definire tante cose, funzioni parziali che possono essere indeterminate per certi argomenti, i predicati (funzioni che ritornano un valore booleano T o F), and e or, le espressioni condizionali (COND, non IF). La ricorsività viene definita come [b]y using conditional expressions we can, without circularity, define functions by formulas in which the defined function occurs, seguono esempi, è una novità. E attenzione che [t]here is no guarantee that the computation determined by a recursive definition will ever terminate and, for example, an attempt to compute n! from our definition will only succeed if n is a non-negative integer. If the computation does not terminate, the function must be regarded as undefined for the given argument.

Sempre tra le cose nuove la distinzione tra Functions and Forms. It is usual in mathematics --outside of mathematical logic-- to use the word 'function' imprecisely and to apply it to forms such as y^2 + x. Because we shall later compute with expressions for functions, we need a distinction between functions and forms and a notation for expressing this distinction. This distinction and a notation for describing it, from which we deviate trivially, is given by Church. Salto ma si arriva a λ, per l'esempio trattato λ((x,y), y^2 +x) che risolve l'ambiguità di f(3,4) essendo ovviamente λ((x,y),y^2+x)(3,4)=19. OK, c'è di più, le variabili sono dummy, possono essere cambiate, cose che adesso si da per scontato ma allora era tutto un mondo nuovo.

Con le funzioni ricorsive lambda diventa inadeguata, vedi l'esempio di sqrt. Qui la proposta non è quella che avrebbe vinto alla lunga, dipende dalla prassi del Fortran, anzi dal codice macchina, si introduce label. Personalmente sono contento di non aver lispato all'epoca, ma le stesse cose le ho fatte, parecchie volte in Fortran (e Basic).

Uh, ancora lungo il paper; pausa 🙂
🔴

03 luglio, 2019

Notarelle storiche sul Lisp - 1


Uno dei miei passatempi è la storia, andare a vedere (o rivedere se ero presente al tempo) cose, fatti, persone e altro ancora che poi sarebbe evoluto, in modo spesso imprevedibile. Per esempio io di Silvio (sì, allui, aqquello) ne ho sentito parlare quando ancora --OK, personale qui, censuro.

Vale anche per la programmazione, ho passato la prima metà della carriera professionale con il Fortran; ma ero nuovo (allora) e propendevo per il 77 avendo contro tutti i vecchi (cioè tutti; quando il capo ha un'opinione quella dev'essere la tua). Ho già raccontato una cosa che voi giovani --tutti quelli più giovani di me-- faticano a credere, ma è codice che si può compilare ed eseguire, vedi qui: Evoluzione - archeologia.

Era codice corrente al tempo. Anzi c'era una generazione precedente che scriveva in assembler (purtroppo non sono più in contatto da tempo con nessuno che mi possa fornire un esempio, che comunque non funzionerebbe ormai, dipendeva dalla macchina). Nel mio caso si parla di cicli, fatti con l'uso di GOTOs; a rigore i GOTO sono mascherati, io li avrei usati (allo stesso modo in cui si sarebbero usati nel Basic) ma i vecchi erano abituati agli IF calcolati.

Ecco l'istruzione IF, quanto e come si è evoluta nel tempo. Il Fortran ha seguito la via tracciata da Algol/Pascal, Basic e tanti altri diventando quello che si usa oggi if then/else if/else/end if --OK non tutti scrivono così.

Il Lisp è diverso e la sintassi dell'if è diversa, particolare, unica: (if test-expr then-expr else-expr); non mi addentro, andrei fuori tema. Ma è una form speciale, valuta una sola delle espressioni in funzione del risultato di test-expr. Io credevo, sbagliandomi, che ci fosse da sempre, cioè da quando c'è il Lisp. E invece no, è arrivata molto dopo. Non è un post giallo e do subito la soluzione: si usava COND (sì allora tutto maiuscolo).

La curiosità su if è nata a seguito di una discussione conseguente a un mio errore (e siccome è un errore mio non metto il link). Non riguardava il Lisp ma Unix e la sua evoluzione Linux, l'if di bc adesso aveva else e ho letto troppo in fretta tanto che mi è sembrato Lisp.

Basta; quest'introduzione è troppo lunga, vengo all'argomento. Elenco e cito documenti trovati online che illustrano (almeno a me, secondo me) la nascita e le prime fasi del linguaggio. Risulta fin da subito che il linguaggio di programmazione che si andrà a proporre è legato, quasi un effetto collaterale, all'intelligenza artificiale --espressione nuova appena creata dallo stesso John McCarthy.

Programs with Common Sense
Programs with Common Sense was probably the first paper on logical AI, i.e. AI in which logic is the method of representing information in computer memory and not just the subject matter of the program. The paper was given in the Teddington Conference on the Mechanization of Thought Processes in December 1958 and printed in the proceedings of that conference. It may also be the first paper to propose common sense reasoning ability as the key to AI.

C'è il PDF, 15 pagine, raccomandatissimo. Allora il computer era una cosa nuova, e allora

Interesting work is being done in programming computers to solve problems which require a high degree of intelligence in humans. However, certain elementary verbal reasoning processes so simple that they can be carried out by any non-feeble minded human have yet to be simulated by machine programs.

[...]

The advice taker is a proposed program for solving problems by manipulating sentences in formal languages.

[...]

The main advantages we expect the advice taker to have is that its behavior will be improvable merely by making statements to it, telling it about its symbolic environment and what is wanted from it. To make these statements will require little if any knowledge of the program or the previous knowledge of the advice taker.

[...] is expected to have much in common with what makes us describe certain humans as having common sense. We shall therefore say that a program has common sense if it automatically deduces for itself a sufficiently wide class of immediate consequences of anything it is told and what it already knows.

Before describing the advice taker in any detail, I would like to describe more fully our motivation for proceeding in this direction. Our ultimate objective is to make programs that learn from their experience as effectively as humans do.

[...]

Sarebbe tutto da copiare ma molto meglio leggerlo di là. Piuttosto l'elenco in 5 punti di cosa advice taker dovrebbe fare:
  1. All behaviors must be representable in the system. Therefore, the system should either be able to construct arbitrary automata or to program in some general purpose programming language;
  2. Interesting changes in behavior must be expressible in a simple way;
  3. All aspects of behavior except the most routine must be improvable. In particular, the improving mechanism should be improvable;
  4. The machine must have or evolve concepts of partial success because on difficult problems decisive successes or failures come too infrequently;
  5. The system must be able to create subroutines which can be included in procedures as units. The learning of subroutines is complicated by the fact that the effect of a subroutine is not usually good or bad in itself. Therefore, the mechanism that selects subroutines should have concepts of interesting or powerful subroutine whose application may be good under suitable conditions.
Un programma enorme, per cominciare [o]f the 5 points mentioned above, our work concentrates mainly on the second.

Ecco si parte da qui. A p.5 c'è "The Construction of the Advice Taker" dove si introducono gli elementi costituenti il linguaggio. Non è ancora il Lisp e la sintassi usata non è quella che sarebbe diventata. È quella che poi avrebbe costituito le M-expressions, M per meta.

Pausa? vero che il Lisp non è ancora comparso ma prossimamente... Probabilmente. Forse.

🔴

22 maggio, 2019

GW-BASIC - quasi - archeologia


Io quando sono arrivati i PC, personal computer, quelli che poi si sarebbero chiamati desktop e sono già obsoleti ormai, lavoravo già. su un mini (che ha un nome giustificabile solo storicamente), il PR1ME 550, e mi sono perso quasi tutta la fase iniziale.

Poi certo, non si vive in una bolla impermeabile, a un certo punto anch'io ne sono stato travolto. Ma non come tanti, non l'ho presa tanto bene. Anche perché ero indaffarato con cose come quelle raccontate qui.

Capita che un collega di allora mi manda un msg dicendomi che --una cosa lunga provo a metterne una parte per iscritto, qui di seguito.

Sul Prime c'era solo il Fortran e quindi usavi quello. Anche quando non lo sapevi: per esempio un messaggio di errore poteva essere **SZ; era compito lasciato a te che SZ stava per size e quindi avevi a che fare con un numero troppo grande (in valore assoluto). Ma con i personal tutto cambiava, addirittura interagivi in italiano.

Non voglio farla lunga, salto i primi modelli, compreso l'M20 di Olivetti, e arrivo al momento in cui IBM e Microsoft avevano vinto (OK, a parte che c'erano anche l'APPLE ][ e l'HP-9816). I nuovi dicevano che il Fortran era troppo complicato (non so se sia vero, riuscivo a usarlo anch'io) e per certi versi insensato, illogico, assurdo (dai! non esageriamo, anche se...) e proponevano qualcosa di più semplice, il BASIC.

C'è chi ha recentemente emulato quello che per IBM e M$ si chiamava GW-BASIC, incredibilmente bene, in Python (sempre lui). Sto parlando di PC-BASIC di Rob Hagemans.

Visto che Rob dice tutto quel che si potrebbe voler sapere e c'è anche il codice (manca solo l'about, chissà se c'è sui socials?) a me non resta che provarlo.


e

No, non ricordavo tutto, qualcosa ma non tutto. Per esempio avevo scritto SQRT e mi subito qualcuno mi ha corretto:


Naturalmente il Web è grande e ricorda (spesso, non sempre non ho ancora trovato --OK, personale, non iteresserebbe a nessuno (tranne me)), ecco qua (sono tutti PDF:


OK, confesso, sempre dallo stesso msg: ci sono anche altre versioni del basic, un elenco qui: Free BASIC Compilers and Interpreters.

🔴