Visto nel Web – 198

Mille. Lo dice il signor WordPress che tiene il conto. Chi l’avrebbe pensato mai! Intanto ecco cosa ho visto nel Web.

Gary Waters

Gary Waters

Google Is Working On A New Type Of Algorithm Called “Thought Vectors”
::: WT VOX

Welcome to Rust-101
::: Ralf Jung

Ubuntu Core Gets Support For Raspberry Pi 2 GPIO and I2C
::: Slashdot

Why Google Wants To Sell You a Wi-Fi Router
::: Slashdot

Swatch plans multiple smartwatches, but they’ll be simple
::: Engadget

Another “big” question
Will scientific fields give rise to hegemonic domain specific [programming] languages (within 5-15 years)?
::: Lambda the Ultimate


Deploying Racket applications on Heroku
::: Alexis King

Why Go and Rust are Competitors
::: Caleb Doxsey

The Top 10 Programming Languages On GitHub, Over Time
::: Slashdot

Io ancora devo capire che cazzo ci fate con ‘sti #smartphone
::: Genjuro75

Twitter bots are trying to silence Mexican protesters
::: Engadget ::: fabiochiusi


Andamento e futuro dell’open source: l’indagine 2015
::: Tech Economy

Linus Torvalds: Security is never going to be perfect
::: ITworld

Windows 95 compie vent’anni

Immutability changes everything!
::: jamesiry

Best/worst thing about #coding
::: reneehlozek


First comes the leak. Then, the tools to parse it. Then, the panic
::: fabiochiusi

Buon compleanno Linux!!!!!
::: rewasp1973 ::: daw985

TweetQureet: a full Golang technology stack
::: Qureet

A Breakdown of the Windows 10 Privacy Policy
::: Slashdot

This hydrogen fuel cell-powered iPhone 6 delivers an entire week of battery life
::: ExtremeTech


Le « Hello World » le plus difficile
::: CommitStrip

Alibaba’s Cloud Computing Group Says Its New Artificial Intelligence Platform Is China’s First
::: TechCrunch

10+1 piccoli particolari (errati) nel rapporto Netics sul caso Pesaro
::: Tech Economy

Convert any Python file into a single line of code which has the same functionality.
una pazzia ma geniale :grin:
::: csvoss

State of the Common Lisp Ecosystem, 2015
::: eudoxia


Massachusetts Boarding School Sued Over Wi-Fi Sickness
questa cosa ogni tanto ritorna, pare sia solo fuffa
::: Slashdot

Più insieme che soli
::: Chiusi nella rete

Linux ha 24 anni
anche RaiNews!
::: RaiNews

How Linux was born, as told by Linus Torvalds himself
::: Ars Technica

This Italian company pioneered innovative startup culture—in the 1930s
::: Quartz


Doing Astronomy with Python
::: Linux Journal

Alfabeto Open: S as “Security”
::: Tech Economy

Python, Machine Learning, and Language Wars. A Highly Subjective Point of View
avendo tempo meriterebbe un post tutto suo, o tutta una serie
::: Sebastian Raschka

I crossed the 75000 reputation mark on Stackoverflow with 1171 #Lisp related answers.
un modello cui ispirarsi :grin:
::: RainerJoswig

Statistics in Python
::: Statistics in Python


Building Python modules with Go 1.5
::: Filippo Valsorda

Facebook Is Now Working On Its Own Digital Assistant Called M
::: Slashdot

How To Keep Microsoft’s Nose Out of Your Personal Data In Windows 10
::: Slashdot

Distribution Release: Scientific Linux 6.7
::: DistroWatch

State al riparo
::: manteblog


Computing Division at the Department of the Treasury, mid 1920s
::: oldpicsarchive

In Praise of the Solo Programmer
::: Slashdot

Windows 10 booms as PC sales collapse
::: ExtremeTech

La gestione del cambiamento secondo #Nokia
::: stefanoepifani

Public Domain should be protected like any other resource
::: copymeorg


RISC OS Open: Raspberry Pi
::: RISC OS Open

Is Office 365 cheaper than OpenOffice and open source?
M$ Pesaro, continua
::: CIO ::: Dario Cavedon (iced) ::: Dario Cavedon (iced)

10 buone ragioni per NON passare a Linux
LOL :wink:
::: Dario Cavedon (iced)

Former Apple CEO Creates an iPhone Competitor
::: Slashdot

Writing code that writes code — with Hack Codegen
::: Facebook Code


US formally demanded Norway extradite Edward Snowden
::: Free Snowden

Quando software libero e sicurezza vanno a braccetto: l’esempio BackBox
::: Tech Economy

Make a GET Request in Nimrod
una segnalazione: Connor è passato a Nim, una promessa tra i linguaggi del futuro
::: Connor Johnson

Embeddable Common-Lisp
::: Common Lisp

Prodi: “Se c’è chi ti impedisce l’analisi è Twitter”
::: fabiochiusi


Stop a Flash dal 1 settembre

Loi de Murphy de Moore
::: CommitStrip

Ubuntu Is the Dominant Cloud OS
::: Slashdot

ES6 In Depth: The Future
::: Mozilla Hacks

Symantec Researchers Find 49 New Modules of Regin Spying Tool
::: Slashdot

Lasp – A Language for Distributed, Eventually Consistent Computations
::: Lasp

Wifi, mobiles… : l’hypersensibilité aux ondes reconnue comme un “handicap grave”
::: Le Point

Nilesh Kurhade

Nilesh Kurhade

Racket – Espressioni regolari – 3

Prima Nugroho

Prima Nugroho

Proseguo, oggi qui: [doc]/guide/regexp.html, anzi qui: [doc]/guide/regexp-assert.html.

Indicazioni elementari

Basic Assertions dice la guida, dimmi te come si fa a tradurre? Anche perché poi sono le regole usuali di sempre, forse.

The assertions ^ and $ identify the beginning and the end of the text string, respectively. They ensure that their adjoining regexps match at one or other end of the text string:


The regexp above fails to match because contact does not occur at the beginning of the text string. In


the regexp matches the last laugh.

The metasequence \b asserts that a word boundary exists, but this metasequence works only with #px syntax. In


the yack in yackety doesn’t end at a word boundary so it isn’t matched. The second yack does and is.

Ecco, questa è nuova :wink: mai fidarsi dei racketeers, sono troppo nerds :wink:

The metasequence \B (also #px only) has the opposite effect to \b; it asserts that a word boundary does not exist. In


the an that doesn’t end in a word boundary is matched.

OK, pronto a passare alla prossima pagina, questa: [doc]/guide/regexp-chars.html.

Caratteri e classi di caratteri

Typically, a character in the regexp matches the same character in the text string. Sometimes it is necessary or convenient to use a regexp metasequence to refer to a single character. For example, the metasequence \. matches the period character.

The metacharacter . matches any character (other than newline in multi-line mode):


The above pattern also matches pat, pit, pot, put, and p8t, but not peat or pfffft.

A character class matches any one character from a set of characters. A typical format for this is the bracketed character class [...], which matches any one character from the non-empty sequence of characters enclosed within the brackets. Thus, #rx"p[aeiou]t" matches pat, pet, pit, pot, put, and nothing else.


Inside the brackets, a - between two characters specifies the Unicode range between the characters. For example, #rx"ta[b-dgn-p]" matches tab, tac, tad, tag, tan, tao, and tap.


An initial ^ after the left bracket inverts the set specified by the rest of the contents; i.e., it specifies the set of characters other than those identified in the brackets. For example, #rx"do[^g]" matches all three-character sequences starting with do except dog.


Note that the metacharacter ^ inside brackets means something quite different from what it means outside. Most other metacharacters (., *, +, ?, etc.) cease to be metacharacters when inside brackets, although you may still escape them for peace of mind. A - is a metacharacter only when it’s inside brackets, and when it is neither the first nor the last character between the brackets.

Bracketed character classes cannot contain other bracketed character classes (although they contain certain other types of character classes; see below). Thus, a [ inside a bracketed character class doesn’t have to be a metacharacter; it can stand for itself. For example, #rx"[a[b]" matches a, [, and b.

Furthermore, since empty bracketed character classes are disallowed, a ] immediately occurring after the opening left bracket also doesn’t need to be a metacharacter. For example, #rx"[]ab]" matches ], a, and b.

Insomma non più sempici del solito :roll:

Alcune classi di caratteri usate sovente

In #px syntax, some standard character classes can be conveniently represented as metasequences instead of as explicit bracketed expressions: \d matches a digit (the same as [0-9]); \s matches an ASCII whitespace character; and \w matches a character that could be part of a “word”.

Following regexp custom, we identify “word” characters as [A-Za-z0-9_], although these are too restrictive for what a Racketeer might consider a “word.”

The upper-case versions of these metasequences stand for the inversions of the corresponding character classes: \D matches a non-digit, \S a non-whitespace character, and \W a non-“word” character.

Remember to include a double backslash when putting these metasequences in a Racket string:


These character classes can be used inside a bracketed expression. For example, #px"[a-z\\d]" matches a lower-case letter or a digit.

Classi di caratteri POSIX

A POSIX character class is a special metasequence of the form [:...:] that can be used only inside a bracketed expression in #px syntax. The POSIX classes supported are:

[:alnum:] — ASCII letters and digits
[:alpha:] — ASCII letters
[:ascii:] — ASCII characters
[:blank:] — ASCII widthful whitespace: space and tab
[:cntrl:] — “control” characters: ASCII 0 to 32
[:digit:] — ASCII digits, same as \d
[:graph:] — ASCII characters that use ink
[:lower:] — ASCII lower-case letters
[:print:] — ASCII ink-users plus widthful whitespace
[:space:] — ASCII whitespace, same as \s
[:upper:] — ASCII upper-case letters
[:word:] — ASCII letters and _, same as \w
[:xdigit:] — ASCII hex digits

For example, the #px"[[:alpha:]_]" matches a letter or underscore.


The POSIX class notation is valid only inside a bracketed expression. For instance, [:alpha:], when not inside a bracketed expression, will not be read as the letter class. Rather, it is (from previous principles) the character class containing the characters :, a, l, p, h.


Sono sicuro che non sono il solo a pasticciare qui :roll:


Un quiz, soluzioni con Python e Racket

bach-origTrovare quel numero che diviso per 2 ha come resto 1, diviso per 3 ha sempre resto 1, e ugualmente diviso per 4, per 5 o per 6 ha sempre resto 1, ma se viene divso per sette dà resto zero.
Federico Peiretti, Il matematico si diverte, Longanesi 2010, p.83. riferito a Claude-Gaspard Bachet.


Claude-Gaspard Bachet è un matemeatico (e non solo) importante, che giustifica l’uso del quiz molto semplice ma devo fare pratica; e poi c’era anche il mio amico GG (prossimamente, forse…).

Ancora una cosa: l’immagine iniziale è presa da Gallica, qui.

Sono anche in regola con le condizioni d’uso. E grazie Gallica e Bibliothèque nationale de France :grin:

Ah! il problema lo trovate a p.199 del libro originale corrispondente a p.218 del PDF.

OK, siccome sono niubbo provo prima con Python.
Occorre trovare quel numero divisibile per 7 che ha modulo 1 per il minimo comune multiplo di {2, 3, 4, 5, 6}. La funzione per il calcolo del minimo comune multiplo (lcm) l’ho copiata da Rosetta Code.

Quindi ecco, Python,


def lcm(*values):
	values = set([abs(int(v)) for v in values])
	if values and 0 not in values:
		n = n0 = max(values)
		while any( n % m for m in values ):
			n += n0
		return n
	return 0

mcm = lcm(2, 3, 4, 5, 6)
found = False
n = 0
while not found:
	n += 1
	found = ((mcm * n + 1) % 7) == 0
print(mcm * n + 1)


E con Racket? bèh, qui sono ancora un po’ (tanto) niubbo ma insomma…

E poi c’è la reference in locale, comodissima:


Sì, bash si lamenta di Firefox ma solo per far vedere che c’è anche lui…

Ma Racket? OK, ecco cgb.rkt:

#lang racket

(define mcm (lcm 2 3 4 5 6))
(define num
  (let cgb ([n 1])
    (if (positive? (modulo (add1 (* n mcm)) 7))
      (cgb (add1 n))
      (add1 (* n mcm)))))
(print num)

La funzione per il calcolo del minimo comune multiplo (lcm) è predefinita :grin:
Il codice è elementare, da niubbo, costruito traducendo quello di Python. Ho usato troppe variabili; ho ripetuto un calcolo numerico una volta più del necessario. Prometto solennemente che in futuro sarò più funzionale.
Giustificazioni: 1) sono niubbo; 2) stavo propagandando Racket a una possibile vittima; con 3) paura di fare una figuraccia.
Poi a demo fatta ho dimenticato il tutto per una settimana, quasi. Ma devo fare pratica, per questo lo pubblico anche se non ottimale :mrgreen:

Nota: corretto un erroraccio, avevo scritto “divisore” al posto di “multiplo”. Grazie a Roberto Giacomelli :grin:

Racket – Espressioni regolari – 2

kk6Oggi, proseguo da qui, copiando qui: [doc]/guide/regexp.html, in particolare qui: [doc]/guide/regexp-match.html.

Usare espressioni regolari

The regexp-match-positions function takes a regexp pattern and a text string, and it returns a match if the regexp matches (some part of) the text string, or #f if the regexp did not match the string. A successful match produces a list of index pairs.


In the second example, the integers 4 and 10 identify the substring that was matched. The 4 is the starting (inclusive) index, and 10 the ending (exclusive) index of the matching substring:


In this first example, regexp-match-positions’s return list contains only one index pair, and that pair represents the entire substring matched by the regexp. When we discuss subpatterns later, we will see how a single match operation can yield a list of submatches.

The regexp-match-positions function takes optional third and fourth arguments that specify the indices of the text string within which the matching should take place.


(il carattere ventesimo è “m” di “my“, il 39esimo lo spazio che precede “stack“)
Note that the returned indices are still reckoned relative to the full text string.

The regexp-match function is like regexp-match-positions, but instead of returning index pairs, it returns the matching substrings:


When regexp-match is used with byte-string regexp, the result is a matching byte substring:


Note: A byte-string regexp can be applied to a string, and a string regexp can be applied to a byte string. In both cases, the result is a byte string. Internally, all regexp matching is in terms of bytes, and a string regexp is expanded to a regexp that matches UTF-8 encodings of characters. For maximum efficiency, use byte-string matching instead of string, since matching bytes directly avoids UTF-8 encodings.

If you have data that is in a port, there’s no need to first read it into a string. Functions like regexp-match can match on the port directly:


The regexp-match? function is like regexp-match-positions, but simply returns a boolean indicating whether the match succeeded:


The regexp-split function takes two arguments, a regexp pattern and a text string, and it returns a list of substrings of the text string; the pattern identifies the delimiter separating the substrings.


If the first argument matches empty strings, then the list of all the single-character substrings is returned.


Thus, to identify one-or-more spaces as the delimiter, take care to use the regexp #rx" +", not #rx" *".


The regexp-replace function replaces the matched portion of the text string by another string. The first argument is the pattern, the second the text string, and the third is either the string to be inserted or a procedure to convert matches to the insert string.


notare l’Unicode nella prima e il . nella seconda (almeno io ci ho dovuto far mente locale).

The regexp-replace* function replaces all matches in the text string by the insert string:


Uhmmm… sì ho messo gli accenti e notare le parentesi quadre, credo se ne parlerà prossimamente :mrgreen:

Racket – Espressioni regolari – 1


Capitolo nuovo, argomento classico e panicante, RE o regexp, qui, [doc]/guide/regexp.html.

La guida ci ricorda che questa (o meglio lei) è una versione modificata di un classico: Dorai Sitaram, “pregexp: Portable Regular Expressions for Scheme and Common Lisp.” 2002.

A regexp value encapsulates a pattern that is described by a string or byte string. The regexp matcher tries to match this pattern against (a portion of) another string or byte string, which we will call the text string, when you call functions like regexp-match. The text string is treated as raw text, and not as a pattern.

La guida ne parla diffusamente ma se non bastasse: Regular Expressions in The Racket Reference provides more on regexps, qui [doc]/reference/regexp.html.

OK, passo a [doc]/guide/regexp-intro.html dove trovo…

Scrivere regexp

Un paio di cose: userò regexp anch’io e poi il “patterns” del titolo originale –al solito– uhmmm, schemi, modelli, ___________.

A string or byte string can be used directly as a regexp pattern, or it can be prefixed with #rx to form a literal regexp value. For example, #rx"abc" is a string-based regexp value, and #rx#"abc" is a byte string-based regexp value. Alternately, a string or byte string can be prefixed with #px, as in #px"abc", for a slightly extended syntax of patterns within the string.

Most of the characters in a regexp pattern are meant to match occurrences of themselves in the text string. Thus, the pattern #rx"abc" matches a string that contains the characters a, b, and c in succession. Other characters act as metacharacters, and some character sequences act as metasequences. That is, they specify something other than their literal selves. For example, in the pattern #rx"a.c", the characters a and c stand for themselves, but the metacharacter . can match any character. Therefore, the pattern #rx"a.c" matches an a, any character, and c in succession.

Note: When we want a literal \ inside a Racket string or regexp literal, we must escape it so that it shows up in the string at all. Racket strings use \ as the escape character, so we end up with two \s: one Racket-string \ to escape the regexp \, which then escapes the .. Another character that would need escaping inside a Racket string is ".

If we needed to match the character . itself, we can escape it by precede it with a \. The character sequence \. is thus a metasequence, since it doesn’t match itself but rather just .. So, to match a, ., and c in succession, we use the regexp pattern #rx"a\\.c"; the double \ is an artifact of Racket strings, not the regexp pattern itself.

The regexp function takes a string or byte string and produces a regexp value. Use regexp when you construct a pattern to be matched against multiple strings, since a pattern is compiled to a regexp value before it can be used in a match. The pregexp function is like regexp, but using the extended syntax. Regexp values as literals with #rx or #px are compiled once and for all when they are read.

The regexp-quote function takes an arbitrary string and returns a string for a pattern that matches exactly the original string. In particular, characters in the input string that could serve as regexp metacharacters are escaped with a backslash, so that they safely match only themselves.


The regexp-quote function is useful when building a composite regexp from a mix of regexp strings and verbatim strings.

Pausa, argomento nuovo (cioè no ma ogni linguaggio lo tratta a modo suo, piccole (o meno piccole) varianti rispetto alla versione cannica, Stephen Kleene, AWK e Perl).


Racket – Input e Output – 3


Continuando da qui oggi –forse– finisco il capitolo di I/O, qui: [doc]/guide/i_o.html anzi qui: [doc]/guide/serialization.html.

Tipi di dati e serializzazione

Che sarebbe la mia traduzione di Datatypes and Serialization.
prefab structure types (see Prefab Structure Types, [qui: [doc]/guide/define-struct.html)] automatically support serialization: they can be written to an output stream, and a copy can be read back in from an input stream:


Other structure types created by struct, which offer more abstraction than prefab structure types, normally write either using #<....> notation (for opaque structure types) or using #(....) vector notation (for transparent structure types). In neither can the result be read back in as an instance of the structure type:


oops! ma


The serializable-struct form defines a structure type that can be serialized to a value that can be printed using write and restored via read. The serialized result can be deserialized to get back an instance of the original structure type. The serialization form and functions are provided by the racket/serialize library.


In addition to the names bound by struct, serializable-struct binds an identifier with deserialization information, and it automatically provides the deserialization identifier from a module context. This deserialization identifier is accessed reflectively when a value is deserialized.

Uhmmm… da pensarci su un po’.
Intanto passo a [doc]/guide/encodings.html.

bytes, characters e encoding

Functions like read-line, read, display, and write all work in terms of characters (which correspond to Unicode scalar values). Conceptually, they are implemented in terms of read-char and write-char.

More primitively, ports read and write bytes, instead of characters. The functions read-byte and write-byte read and write raw bytes. Other functions, such as read-bytes-line, build on top of byte operations instead of character operations.

In fact, the read-char and write-char functions are conceptually implemented in terms of read-byte and write-byte. When a single byte’s value is less than 128, then it corresponds to an ASCII character. Any other byte is treated as part of a UTF-8 sequence, where UTF-8 is a particular standard way of encoding Unicode scalar values in bytes (which has the nice property that ASCII characters are encoded as themselves). Thus, a single read-char may call read-byte multiple times, and a single write-char may generate multiple output bytes.

The read-char and write-char operations always use a UTF-8 encoding. If you have a text stream that uses a different encoding, or if you want to generate a text stream in a different encoding, use reencode-input-port or reencode-output-port. The reencode-input-port function converts an input stream from an encoding that you specify into a UTF-8 stream; that way, read-char sees UTF-8 encodings, even though the original used a different encoding. Beware, however, that read-byte also sees the re-encoded data, instead of the original byte stream.

OK, infine [doc]/guide/io-patterns.html.

Patterns di I/O

If you want to process individual lines of a file, then you can use for with in-lines:


If you want to determine whether “hello” appears in a file, then you could search separate lines, but it’s even easier to simply apply a regular expression (see Regular Expressions [prossimamente]) to the stream:


If you want to copy one port into another, use copy-port from racket/port, which efficiently transfers large blocks when lots of data is available, but also transfers small blocks immediately if that’s all that is available:



Racket – Input e Output – 2

kk0Continuo da qui, oggi qui: [doc]/guide/i_o.html, anzi in dettaglio qui:[doc]/guide/default-ports.html.

Porte di default

For most simple I/O functions, the target port is an optional argument, and the default is the current input port or current output port. Furthermore, error messages are written to the current error port, which is an output port. The current-input-port, current-output-port, and current-error-port functions return the corresponding current ports.


If you start the racket program in a terminal, then the current input, output, and error ports are all connected to the terminal. More generally, they are connected to the OS-level stdin, stdout, and stderr. In this guide, the examples show output written to stdout in purple, and output written to stderr in red italics.



OOPS! non vale quanto detto nella guida; non da me. Provato a eseguirla anche come script con lo stesso risultato. Ma who cares? :wink:

The current-port functions are actually parameters, which means that their values can be set with parameterize.

Note: See Dynamic Binding [doc]/guide/parameterize.html: parameterize for an introduction to parameters.

Example: Attenzione!!! con questo esempio (dopo averlo modificato per completarlo) sono riuscito a bloccare il ‘puter in modo assoluto e sono ricorso all’hard reset; rimandato quindi a quando sarò meno niubbo :wink:

(let ([s (open-output-string)])
    (parameterize ([current-error-port s])
    (get-output-string s))

Ma mica finisce qui, anzi passo subito alla pagina successiva: [doc]/guide/read-write.html.

Leggere e scrivere dati

As noted throughout Built-In Datatypes [Racket – tipi di dati built-in – 1], Racket provides three ways to print an instance of a built-in value:

  • print, which prints a value in the same way that is it printed for a REPL result; and
  • write, which prints a value in such a way that read on the output produces the value back; and
  • display, which tends to reduce a value to just its character or byte content—at least for those datatypes that are primarily about characters or bytes, otherwise it falls back to the same output as write.

Here are some examples using each:


Overall, print corresponds to the expression layer of Racket syntax, write corresponds to the reader layer, and display roughly corresponds to the character layer.

The printf function supports simple formatting of data and text. In the format string supplied to printf, ~a displays the next argument, ~s writes the next argument, and ~v prints the next argument:


After using write, as opposed to display or print, many forms of data can be read back in using read. The same values printed can also be parsed by read, but the result may have extra quote forms, since a printed form is meant to be read like an expression:



Una nota sulla gestione dei files e su Racket tutto

john-belushi-college-obama-posterIl post iniziale sull’I/O mi ha lasciato un qualcosa in sospeso.
Tutto OK, semplice, funziona ma…
Poi ripensandoci mi sono venuti in mente cose che si fanno abitualmente e chissà come si faranno con Racket?
Per esempio appendere testo a un file ( un log) oppure aprire un file in scrittura senza sapere se già ne esiste uno con quel nome o ancora _________. Ecco mille casi. A me queste cose vengono in mente quando sono lontano dal ‘puter, a volte anche in sonno mi sveglio con la fissa “come si fa?”.

E allora per auto-tranquillizzarmi mi dico (si mi parlo da solo, sarà grave?) che appena posso provo, non è il caso di preoccuparsi, mettere il carro davanti ai buoi :roll:

Ecco, adesso che ho riaperto la guida ho la conferma che non era il caso. C’è tutto sulla guida, nel caso in oggetto in File Ports di The Racket Reference, in locale in [doc]/reference/file-ports.html.

In questa pagina vengono descritte (se ho contato bene) dodici procedure, probabilmente più di quelle che servono. E resto tranquillizzato dal verificare –ancore una volta– la completezza e bontà della documentazione di Racket (e famiglia, mica solo lui).

Ecco adesso devo dire un’altra cosa, su un documento –al solito– molto bene. E speciale, si tratta infatti di The Racket Manifesto.

L’ho letto tutto un paio di volte, non ne ho (ancora) parlato perché un po’ m’intimidisce ma ecco a p.13 si trova:

Racket’s key advantage is its syntax extension system. It makes experienced programmers extremely productive, but it comes with an extraordinarily steep learning curve. Its syntax elaboration algorithm is hard to understand; its toolbox is large and complex; and it has some brittle, unexplored corners that occasionally trip up even experienced programmers. The situation calls for simplifications of the syntax system and for the creation of a smooth ramp for the toolbox (in terms of both tools and documentation).

Ecco. Se non fossi abbastanza incosciente forse mi verrebbe da domandarmi se ce la posso fare. Vero che non ho l’assillo di scadenze (e non mi preoccupano le scarse visite del blog) ma in fondo-in fondo, solo poco-poco ma sì, OK, panico!


D’altro canto: When the going gets tough, the tough get going, come si dice dalle mie parti. E io un po’ a Bluto assomiglio, vero? Altrimenti –se del caso– potrei sempre ripiegare su Alf.

Racket – Input e Output – 1


Oggi inizio un nuovo capitolo, qui: [doc]/guide/i_o.html.

Input e output

Un po’ di terminologia, sapete ognuno usa la sua e quelli di Racket (tutti über-nerds) ovviamente non fanno eccezione. Continuo a curiosare in PLT e ci sono davvero tante cose, per esempio qui :grin:

A Racket port corresponds to the Unix notion of a stream (not to be confused with racket/stream‘s streams).

A Racket port represents a source or sink of data, such as a file, a terminal, a TCP connection, or an in-memory string. Ports provide sequential access in which data can be read or written a piece of a time, without requiring the data to be consumed or produced all at once. More specifically, an input port represents a source from which a program can read data, and an output port represents a sink to which a program can write data.

Ecco, pronto a passare qui: [doc]/guide/ports.html.

Varietà di porte

Various functions create various kinds of ports. Here are a few examples:

Files: The open-output-file function opens a file for writing, and open-input-file opens a file for reading.


e poi…


If a file exists already, then open-output-file raises an exception by default. Supply an option like #:exists 'truncate or #:exists 'update to re-write or update the file:


Nota: ho aggiunto newline (si poteva usare anche il solito “\n“) perché altrimenti il prompt del terminale è fuori posto :wink:

Instead of having to match open-input-file and open-output-file calls, most Racket programmers will instead use call-with-output-file, which takes a function to call with the output port; when the function returns, the port is closed. Questa è una cosa che viene direttamente dal Lisp, ne avevo parlato dettagliatamente quando studiavo l’ottimo Peter Seibel.


Strings: The open-output-string function creates a port that accumulates data into a string, and get-output-string extracts the accumulated string. The open-input-string function creates a port to read from a string.


TCP Connections: The tcp-connect function creates both an input port and an output port for the client side of a TCP communication. The tcp-listen function creates a server, which accepts connections via tcp-accept.


Process Pipes: The subprocess function runs a new process at the OS level and returns ports that correspond to the subprocess’s stdin, stdout, and stderr. (The first three arguments can be certain kinds of existing ports to connect directly to the subprocess, instead of creating new ports.)


esattamente come


Internal Pipes: The make-pipe function returns two ports that are ends of a pipe. This kind of pipe is internal to Racket, and not related to OS-level pipes for communicating between different processes.


OK, mi piace. Mi viene da fare il paragone con il (vecchio e più macchinoso) I/O del Common Lisp; deve aggiornasi, imho.


Ma i giovani conoscono i file di testo?

es0Un post estivo, anche se ormai l’estate sta finendo (cit. per chi se la ricorda). Pare questi post piacciano e allora ecco…

Capitato recentemente. Leggo la bozza quasi definitiva di una tesina (un compito delle vacanze) e prendo appunti. Io che sono vecchio uso un editor normale, Gedit –OK ci sono Emacs e vi ma ormai…– che, ovviamente, produce un file di testo, niente fronzoli tipo font, neretto, sottolineato, corsivo, colori e compagnia bella. Se mi ricordo metto anche l’estensione .txt. E ci sono anche i caratteri accentati, mica solo il set ASCII, tutto l’Unicode.

OK, fatto, salvato, copiato su una chiavetta USB e andato –a piedi, roba di pochi minuti– a casa dello studente.
Qui sono cominciati i fatti che rendono la vita interessante e mi permettono di scrivere questo post. Stavo per dire guai ma sarebbe eccessivo, troppo.
Occorre precisare che il computer del giovane studente (modello, davvero bravo come pochi) ha Windows 8 come sistema operativo. E un antivirus che gode di molta considerazione per via di spiacevoli episodi del recente passato, ma non voglio andare OT.

Il mio file, passato il controllo dell’Ufficio Immigrazione che ha preteso di scannare tutto il driver mobile, è finito, con altri millemila, sul desktop.

Doppio click per aprirlo e –sorpresa– non si vedono gli a-capo. Già Blocco note|Notepad pretende CR-LF invece del solito (per Linux) LF. Che fare?
Ovviamente è da escludere l’installazione di alcunché, anzi il web è considerato pericoloso.
La prima idea è stata quella di visualizzarlo nel browser, c’è Chrome, lo lancio, riduco in finestra e ci droppo sopra il mio file di testo.


L’immagine è dal mio ‘puter, con Firefox, ma è simile a quella di cui sto raccontando.
Uhmmm… gli a-capo ci sono ma i caratteri fuori dal set ASCII non vengono visualizzati correttamente. Sì, si potrebbe dire al browser … ma così al volo, poi va a finire che ci faccio una figura barbina, già vengo visto come lunatico che uso Linux con tutte quelle diavolerie esotiche come i file di testo.

La soluzione, semplice e immediata, è di creare un documento tipo Word –in realtà LibreOffice, ormai usano quello anche loro–, aprirlo e incollarci dentro il testo del file di testo. È un’operazione immediata. Funziona. La dimensione del nuovo documento è di 22.5 kB, contro i 4.9 dell’originale.


Però, questi giovani: sono molto più avanzati di me, sanno messaggiare con lo smartphone componendo i testi (brevi, sintetici) usando con una velocità che implica effetti relativistici i pollici, opponibili, quelli li avrei anch’io ma la sola idea mi spaventa da non dire.

Ma non conoscono gli elementi basilari, come il file di testo. E mettono tutto sul desktop. E usano un sacco sakko di maiuscole. E usano termini come “cartella”, “app”, “scaip”. Tutte cose che non so, a me nessuno dice mai niente :mrgreen:


Ricevi al tuo indirizzo email tutti i nuovi post del sito.

Unisciti agli altri 88 follower