cit. & loll – 30

Post corto che i ‘mericani pensa a Donald J (J sta per Silvio) 😜

u-and-i

Tried to make a joke about integers
::: codepo8

This just happened?
::: scottrudy

Yes, much more sense!
::: Flavio_MfM

Dad, what was the internet like in 1999?
::: codinghorror

16426172_1396408507099695_184776215437178279_n

Spotted on a T-shirt
::: jakevdp

Finalmente la RTTY (radiotelescrivente) funziona
::: Facebook

I put my new networking zine online so you can read it!
::: b0rk

Being wrong on the internet is the best way to learn
::: amasad

c4f9ut2vcaamfdd

Lo so, anche io sto dando il mio contributo a farmi profilare…
::: nesistweets

It’s been a year since I switched from multiple 22” 1080p monitors to a single 43” 2160p
::: TomNomNom

I’m not sure I am smart enough
::: wallingf

are so 1980s!
::: whitequark

harry-potter

Bash – elencare solo i files

nikon-small-world-head-of-a-skinbow-zebrafish-larvae

È solo un gioco, di quelli senza senso, ma ecco un quiz su Bash o shells affini: qual è l’opzione per elencare solo i files e non le directories?
Uh! ce l’ho qui sulla punta della lingua, ho detto incautamente. Prova -f o -F o -t o -T. No fai ls --help. Azt! no 👿

Poi stante che quando il gioco si fa duro (inizio-cit.) e anch’io ci provo. Googlando un po’ perché mica è facile.

Vero che c’è il comando run-parts che run scripts or programs in a directory.

Sì, ecco la mia interpretazione; apre il file .html precedentemente salvato in locale con Firefox (per esempio quelli di Stack Overflow), funziona anche con nomi con spazi, insomma sarebbe OK.

#!/bin/bash

C=$1
firefox "$(run-parts --list --regex "^$C.*" .)"

Ma l’idea iniziale era di usare ls, comando cui sono affezionato, da trent’anni 😜

Si può fare! (cit.), ecco uff:

#!/bin/bash

C="$1*"
firefox "$(find ./$C -maxdepth 0 -type f)"

sì 😜 ho barato: niente ls ma find –sono affezionato anche a quello 😜

lsf

:mrgreen:

SICP – cap. 2 – cosa s’intende per dati? – 6

Kazimir Majorinc

Kazimir Majorinc

Continuo da qui copiando qui.

We began the rational-number implementation in 2.1.1 [qui] by implementing the rational-number operations add-rat, sub-rat, and so on in terms of three unspecified procedures: make-rat, numer, and denom. At that point, we could think of the operations as being defined in terms of data objects—numerators, denominators, and rational numbers—whose behavior was specified by the latter three procedures.

But exactly what is meant by data? It is not enough to say “whatever is implemented by the given selectors and constructors.” Clearly, not every arbitrary set of three procedures can serve as an appropriate basis for the rational-number implementation. We need to guarantee that, if we construct a rational number x from a pair of integers n and d, then extracting the numer and the denom of x and dividing them should yield the same result as dividing n by d. In other words, make-rat, numer, and denom must satisfy the condition that, for any integer n and any non-zero integer d, if x is (make-rat n d), then

s149

In fact, this is the only condition make-rat, numer, and denom must fulfill in order to form a suitable basis for a rational-number representation. In general, we can think of data as defined by some collection of selectors and constructors, together with specified conditions that these procedures must fulfill in order to be a valid representation.

This point of view can serve to define not only “high-level” data objects, such as rational numbers, but lower-level objects as well. Consider the notion of a pair, which we used in order to define our rational numbers. We never actually said what a pair was, only that the language supplied procedures cons, car, and cdr for operating on pairs. But the only thing we need to know about these three operations is that if we glue two objects together using cons we can retrieve the objects using car and cdr. That is, the operations satisfy the condition that, for any objects x and y, if z is (cons x y) then (car z) is x and (cdr z) is y. Indeed, we mentioned that these three procedures are included as primitives in our language. However, any triple of procedures that satisfies the above condition can be used as the basis for implementing pairs. This point is illustrated strikingly by the fact that we could implement cons, car, and cdr without using any data structures at all but only using procedures. Here are the definitions:

(define (cons x y)
  (define (dispatch m)
    (cond ((= m 0) x)
          ((= m 1) y)
          (else 
           (error "Argument not 0 or 1:
                   CONS" m))))
  dispatch)

(define (car z) (z 0))
(define (cdr z) (z 1))

This use of procedures corresponds to nothing like our intuitive notion of what data should be. Nevertheless, all we need to do to show that this is a valid way to represent pairs is to verify that these procedures satisfy the condition given above.

The subtle point to notice is that the value returned by (cons x y) is a procedure—namely the internally defined procedure dispatch, which takes one argument and returns either x or y depending on whether the argument is 0 or 1. Correspondingly, (car z) is defined to apply z to 0. Hence, if z is the procedure formed by (cons x y), then z applied to 0 will yield x. Thus, we have shown that (car (cons x y)) yields x, as desired. Similarly, (cdr (cons x y)) applies the procedure returned by (cons x y) to 1, which returns y. Therefore, this procedural implementation of pairs is a valid implementation, and if we access pairs using only cons, car, and cdr we cannot distinguish this implementation from one that uses “real” data structures.

s150

The point of exhibiting the procedural representation of pairs is not that our language works this way (Scheme, and Lisp systems in general, implement pairs directly, for efficiency reasons) but that it could work this way. The procedural representation, although obscure, is a perfectly adequate way to represent pairs, since it fulfills the only conditions that pairs need to fulfill. This example also demonstrates that the ability to manipulate procedures as objects automatically provides the ability to represent compound data. This may seem a curiosity now, but procedural representations of data will play a central role in our programming repertoire. This style of programming is often called message passing, and we will be using it as a basic tool in Chapter 3 [prossimamente, nel lontano futuro 😊] when we address the issues of modeling and simulation.

Uhmmmm… da pensarci su 😙 😜 🚀
:mrgreen:

Interpreti, introduzione alla programmazione e una segnalazione

cover

Questo post fa parte di una classe per adesso vuota –o quasi- su cose che avrei voluto fare e spesso manco lo sapevo e adesso è tardi. Perché bisognerebbe essere giovani e possibilmente ‘mericani o tanto bravi che ci finisci là perché ti mandano o ti chiamano o –OK, sogni a occhi aperti ma semen in anno licet dirne kwalcuna 😜
Inoltre ci sono gli interpreti, devo ammettere che quello che dicevo negli anni ’80-90 non era vero. Nella classe di post di cui sopra ci sarà anche la mia apologizzazione 😡

Non so se conoscete il prof David Evans dell’UVa. Io no ma vorrei. Per tanti motivi, quelli detti precedentemente e poi dalle foto si vede che l’ambiente è accogliente. Magari bisogna studiare secco forte. Ma si può fare, si deve fare 😄

Il testo che ha usato in anni recenti —Introduction to Computing— disponibile nel Web l’ho letto tutto d’un fiato approfittando dell’influenza 😙

Mi viene voglia di citarne un po’.
A pagina 39 David dice che linguaggio useranno per la prima parte del corso (che ricordo è un corso introduttivo): The programming system we use for the first part of this book is  in a programming language named Scheme. A Scheme interpreter interprets a Scheme program and executes it on the machine processor. Uh! Scheme 😄
E continua: Scheme was developed at MIT in the 1970s by Guy Steele and Gerald Sussman, based on the LISP programming language that was developed by John McCarthy in the 1950s. Although many large systems have been built using Scheme, it is not widely used in industry. It is, however, a great language for learning about computing and programming. The primary advantage of using Scheme to learn about computing is its simplicity and elegance. The language is simple enough that this chapter covers nearly the entire language. […] By contrast, some programming languages that are widely used in industrial programming such as C++ and Java require thousands of pages to describe, and even the world’s experts in those languages do not agree on exactly what all programs mean. Ah! ma allora anticamente quando facevo paragoni tra Fortran (compilato) e Basic (interpretato) era colpa –anche– dell’ambiente industriale (e forse anche del NWO 👽).
Ci sono diversi interpreti Scheme e indovinate? Although almost everything we describe should work in all Scheme interpreters, for the examples in this book we assume the DrRacket programming environment which is freely available from http://racket-lang.org/. Uh! quello che uso io 😄

Nelle pagine 40-52 descrive tutto il linguaggio; e ci sono anche gli esercizi –da fare!
At this point, we have covered enough of Scheme to write useful programs (even if the programs we have seen so far seem rather dull). In fact […] we have covered enough to express every possible computation! We just need to combine these constructs in more complex ways to perform more interesting computations.

Poi il corso— il libro diventa più normale, a parte il fatto di usare Scheme al posto di Python o Java o C++ 😄

A pagina 78 Davide precopia il mio nuovo logo:
cons
A dire il vero il mio logo l’aveva precopiato LMI e Rainer Joswig me l’aveva fatto notare.

Salto, mica posso copiare tutto.  A p.123 si trova: The power of computers comes from their programmability. Universal computers can be programmed to execute any algorithm. The Turing Machine model provides a simple, abstract, model of a computing machine. Every algorithm can be implemented as a Turing Machine, and a Turing Machine can simulate any other reasonable computer. Cosa non nuova ma è un corso introduttivo.

Perdono il prof che non conosce il latino e interpreta male il nome di Leonardo Pisano, p.127.
In compenso c’è la visualizzazione di un ad albero non bilanciato che non dimenticherò più:

umba-tree
Non ho dimenticato che volevo parlare degli interpreti che guarda caso sono introdotti nel capitolo 11, con citazioni di Lewis Carroll e Edsger W. Dijkstra.
Languages are powerful tools for thinking. Different languages encourage different ways of thinking and lead to different thoughts. Hence, inventing new languages is a powerful way for solving problems. We can solve a problem by designing a language in which it is easy to express a solution and implementing an interpreter for that language.

An interpreter is just a program. As input, it takes a specification of a program in some language. As output, it produces the output of the input program. Implementing an interpreter further blurs the line between data and programs, […] by passing procedures as parameters and returning new procedures as results. Programs are just data input for the interpreter program. The interpreter determines the meaning of the program.

To implement an interpreter for a given target language we need to:

  • Implement a parser that takes as input a string representation of a program in the target language and produces a structural parse of the input program. The parser should break the input string into its language components, and form a parse tree data structure that represents the input text in a structural way.
  • Implement an evaluator that takes as input a structural parse of an input program, and evaluates that program. The evaluator should implement the target language’s evaluation rules. Our target language is a simple subset of Scheme we call Charme. The Charme language is very simple, yet is powerful enough to express all computations (that is, it is a universal programming language). Its evaluation rules are a subset of the stateful evaluation rules for Scheme. The full grammar and evaluation rules for Charme are given in Section 11.3. The evaluator implements those evaluation rules.
    Section 11.4 illustrates how changing the evaluation rules of our interpreter opens up new ways of programming.

Sì, si costruisce un interprete nuovo di pakka: Charme. Adesso si potrebbe pensare che siccome finora si è usato Scheme e vogliamo farne una variante useremo –logicamente– Scheme. E invece no!

We use Python instead of Scheme to implement our Charme interpreter for a few reasons. The first reason is pedagogical: it is instructive to learn new languages. As Dijkstra’s quote at the beginning of this chapter [non riportata] observes, the languages we use have a profound effect on how we think. This is true for natural languages, but also true for programming languages. Different languages make different styles of programming more convenient, and it is important for every programmer to be familiar with several different styles of programming. All of the major concepts we have covered so far apply to Python nearly identically to how they apply to Scheme, but seeing them in the context of a different language should make it clearer what the fundamental concepts are and what are artifacts of a particular programming language.

The grammar for Python is quite different from the Scheme grammar, so Python programs look very different from Scheme programs. The evaluation rules, however, are quite similar to the evaluation rules for Scheme.
Like Scheme, Python is a universal programming language. Both languages can express all mechanical computations. For any computation we can express in Scheme, there is a Python program that defines the same computation. Conversely, every Python program has an equivalent Scheme program.

E qui parte con la costruzione di Charme. Non ho rifatto tutto sul mio ‘puter ma non sembra poi tanto difficile (d’altronde conosco un paio di bambini sui 10 anni che parlano correttamente cinese 😙).

Ecco. Un corso che mi sarebbe piaciuto fare, illo tempore, e un argomento da approfondire, gli interpreti. E i linguaggi che si usano nel corso sono quelli che uso (o vorrei usare) anch’io.
C’è anche, proprio alla fine, una giustificazione almeno parziale per quello che pensavo da giovane: Although today’s computers can do amazing things, many of which could not even have been imagined twenty years ago, there are problems that can never be solved by computing. E sì non si può fare tutto 🤖

:mrgreen:

NumPy – 8 – Profiling e timing

mib0

Sempre su IPython copio qui continuando da qui.

Uno scrive, probabilmente non nel modo più efficiente, sapete com’è, dice Knuth “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil“.

But once you have your code working, it can be useful to dig into its efficiency a bit.
IPython provides access to a wide array of functionality for this kind of timing and profiling of code. Here we’ll discuss the following IPython magic commands:

  • %time: Time the execution of a single statement
  • %timeit: Time repeated execution of a single statement for more accuracy
  • %prun: Run code with the profiler
  • %lprun: Run code with the line-by-line profiler
  • %memit: Measure the memory use of a single statement
  • %mprun: Run code with the line-by-line memory profiler

The last four commands are not bundled with IPython–you’ll need to get the line_profiler and memory_profiler extensions, which we will discuss in the following sections.

Controllare i tempi di porzioni di codice con %timeit e %time

%timeit
np46
%time
np47
For %time as with %timeit, using the double-percent-sign cell magic syntax allows timing of multiline scripts:

np48

For more information on %time and %timeit, as well as their available options, use the IPython help functionality (i.e., type %time? at the IPython prompt).

Profiling script interi con %prun
Python contains a built-in code profiler (which you can read about in the Python documentation), but IPython offers a much more convenient way to use this profiler, in the form of the magic function %prun.

np49

The result is a table that indicates, in order of total time on each function call, where the execution is spending the most time. In this case, the bulk of execution time is in the list comprehension inside sum_of_lists. From here, we could start thinking about what changes we might make to improve the performance in the algorithm.
For more information on %prun, as well as its available options, use the IPython help functionality (i.e., type %prun? at the IPython prompt).

È possibile profilare singole linee con %lprun. Bisogna installare line_profiler, cosa che non faccio.
L’uso della memoria si profila con %memit e %mprun, previa installazione di memory_profiler.

Sono tutte operazioni specialistiche, da approfondire se dovessero servire, per adesso le metto tra le cose da fare 😉

:mrgreen:

SICP – cambio versione HTML

c3143noxaaaklr_
Niente panico 😜  anzi gaudium magnum 😄 come forse già detto dal prossimo post i riferimenti saranno alla versione di Andres Raba –sarabander– di cui non ho trovato info ontehtoobz. Anche se il Git risulta non aggiornato recentemente. In ogni caso Andres Rockz 😄
A me nessuno dice mai niente A me l’ha detto b3h3m0th 😄 che seguo dall’antichità con questo tweet.

Insomma da adesso in poi copio qui.

1500x500
Ah! quasi dimenticavo: grazie behem0th 🚀

Aggiornamento
Ci sono ontehtobbz lettori über-assay-anzi-di-più 😀
Prendi Vinnie über-assay-anzi-di-più rockz! 😀 e mi fa notare che non ho citato in questo post la versione Interactive SICP di zodiacLi Xuanji.

Vinnie ha ragione, e Li Xuanji rockz! 😀
Da parlarne ancora. Con il rischio la possibilità di altre osservazioni di quelle che sembrano richiami e invece sono integrazioni benvenute.

Ebbene sì, io sono per fare gli esercizi, sono lento di comprendonio e devo vedere se ho capito; meglio se offline.
zodiac Li si occupa di interpreti e —kwasy panico kwy— non subito ma sto scrivendo qualcosa su, non solo Li 😳

Prossimamente… forse… :mrgreen:

:mrgreen:

SICP – cap. 2 – abstraction barriers – esercizi – 5

nikon-small-world-crystals-of-salicin-a-painkiller-extracted-from-willow-tree-bark

Continuo da qui con gli esercizi, sono qui.

Exercise 2.3.  Implement a representation for rectangles in a plane. (Hint: You may want to make use of exercise 2.2. [post precedente]) In terms of your constructors and selectors, create procedures that compute the perimeter and the area of a given rectangle. Now implement a different representation for rectangles. Can you design your system with suitable abstraction barriers, so that the same perimeter and area procedures will work using either representation?

Può essere semplice o meno, è in qualche misura indefinito (ecco a cosa servono i prof, interagire e chiarire). Per esempio abbiamo le funzioni trigonometriche sin e cos oltre a quelle dell’esercizio precedente? Altrimenti diventa meno semplice fare cose così:

s148

I miei nerds di riferimento si sono limitati alla versione blu. Al solito über la pagina di Bill the Lizard, c’è tutto, spiegato come si deve. Prof fategli delle proposte ancora prima di promuoverlo 😜
sicp-ex è OK anche se meno spiegato di Bill.
OK anche Drewiki 😀

La mia versione non la metto (non aggiungerebbe niente), meglio seguire Bill 😄

:mrgreen:

Visto nel Web – 273

Fresco e nebbioso di giornata ecco cosa ho wisto nel Web 😄

c3xkyykwmaaawnx

Server Runs Continuously For 24 Years
#:Web, Internet
::: Slashdot

Time to take a stand
magari quando lo pubblico è tutto finito ma è da citare
#:politica
::: Stack Overflow

What Is the oldest computer program still in use?
#:storia
::: CompSciFact

Get “Non-Technical” People Writing Code Too
#:programming, codice, snippet
::: ThePracticalDev

Microsoft Reports New Subscribers For Office 365 Plunged 62%
#:tools, componenti software
::: Slashdot

c3ltgnuxuamofji

A short #Python class puzzle
#:programming, codice, snippet
::: reuvenmlerner

Update: the @ACLU just ran the numbers again
#:politica
::: brianstelter

Children as Data Scientists — New paper about an awesome system
#:programming, codice, snippet
::: makoshark

Front-End Developer Handbook 2017
#:manuali, how to
::: newsycombinator

Structure and Interpretation of Computer Programs – Interactive Version
un altra versione del classico SICP
#:lisp(s)
::: xuanji

c3mdx23wqae2nmb

Timeline of Computer History
ehi! foto i news nuove 😀 😉
#:storia
::: Computer History Museum

LISP Information and Resources
This is a collection of Lisp / Scheme books and online resources
#:lisp(s)
::: Bill Bradford

The Racket PPA for Ubuntu has been updated to v6.8!
#:lisp(s)
::: racketlang

New compiler variation optimizes parallel code “better than any commercial or open-source compiler”
#:programming, codice, snippet
::: MIT_CSAIL

New zine: “Networking! ACK!”
#:programming, codice, snippet
::: b0rk

feyman-phd

Motore di ricerca per trovare pubblicazioni scientifiche e libri
funziona 😀 spero siano OK i downloads 😆
#:Web, Internet #:tools, componenti software
::: MoniaMarchettin

Apple Sets a New Record For iPhone Sales
#:dispositivi mobili
::: Slashdot

LibreOffice 5.3 Released, Called ‘Most Feature-Rich Release’ Ever
#:tools, componenti software #:free open source software
::: dcavedon

typestring – C++11/14 strings for direct use in template parameter lists
#:programming, codice, snippet
::: oss_cpp

Oh My Giraffe! (a cute endless runner game) is Now Available on Ubuntu
#:games
::: dcavedon

c3rhxthwcakncq_

Contrasting Word and LaTeX
dipende da cosa vuoi fare, la complessità; l’utente normale è sotto
#:tools, componenti software
::: TeXtip

Why I am learning Rust now
#:linguaggi di programmazione
::: ThePracticalDev

…and there goes the evening/night, trying to tame the CLI!
le so! le sooo!!! 😊
::: Flavio_MfM

Mathematics for Computer Science
#:manuali, how to
::: CompSciFact

Announcing #rustlang 1.15
#:linguaggi di programmazione
::: rustlang

c3w7qd-wqaacbsz

How to Install LibreOffice 5.3 on Ubuntu
#:free open source software
::: dcavedon

Indian court in a landmark case: equal access to education is more important than #copyright
#:copyright
::: communia_eu

Just announced an enormous longitudinal dataset from @Scratch
#:linguaggi di programmazione
::: makoshark

Dependency injection overview
#:programming, codice, snippet
::: ThePracticalDev

Amazon Now Has More Than 341,000 Employees — Added 110,000 People Last Year
#:ditte
::: Slashdot

16265345_1292522057453631_7108479207190428304_n

In what way would learning Smalltalk make me a better programmer?
#:programming, codice, snippet
::: Quora

Five years of public activity in the Scratch online programing community
#:programming, codice, snippet
::: danyoel ::: makoshark

In memoria del Prof. Antonio Cantaro
#:protagonisti
::: Dario Cavedon

New HTML5 version of SICP
cioè sempre la 2nd edition ma in HTML5
#:lisp(s) #:manuali, how to
::: b3h3m0th

Basic Malware Analysis Tools
#:sicurezza, spionaggio, virus
::: HackingTutors

tumblr_morjq9zoc91s01qkyo1_400

NumPy – 7 – Errori e debugging

cvp

Copio qui continuando da qui.

Code development and data analysis always require a bit of trial and error, and IPython contains tools to streamline this process. This section will briefly cover some options for controlling Python’s exception reporting, followed by exploring tools for debugging errors in code.

Controllare le eccezioni con %xmode
Most of the time when a Python script fails, it will raise an Exception. When the interpreter hits one of these exceptions, information about the cause of the error can be found in the traceback, which can be accessed from within Python. With the %xmode magic function, IPython allows you to control the amount of information printed when the exception is raised. Consider the following code:

np40

Using the %xmode magic function (short for Exception mode), we can change what information is printed.

%xmode takes a single argument, the mode, and there are three possibilities: Plain, Context, and Verbose. The default is Context, and gives output like that just shown before. Plain is more compact and gives less information:

np41

e

np42

This extra information can help narrow-in on why the exception is being raised. So why not use the Verbose mode all the time? As code gets complicated, this kind of traceback can get extremely long. Depending on the context, sometimes the brevity of Default mode is easier to work with.

Debugging quando non basta la traceback
IPython con il comando magigo %debug è perhaps the most convenient interface to debugging. If you call it after hitting an exception, it will automatically open an interactive debugging prompt at the point of the exception. The ipdb prompt lets you explore the current state of the stack, explore the available variables, and even run Python commands!

np43

E questo è solo l’inizio, consente di andare oltre

np44

This allows you to quickly find out not only what caused the error, but what function calls led up to the error.
If you’d like the debugger to launch automatically whenever an exception is raised, you can use the %pdb magic function to turn on this automatic behavior:

np45

Finally, if you have a script that you’d like to run from the beginning in interactive mode, you can run it with the command %run -d, and use the next command to step through the lines of code interactively.

Lista (parziale) dei comandi di debugging
There are many more available commands for interactive debugging than we’ve listed here; the following table contains a description of some of the more common and useful ones:

Command     Description
list        Show the current location in the file
h(elp) 	    Show a list of commands, or find help on a specific command
q(uit) 	    Quit the debugger and the program
c(ontinue)  Quit the debugger, continue in the program
n(ext) 	    Go to the next step of the program
<enter>     Repeat the previous command
p(rint)     Print variables
s(tep) 	    Step into a subroutine
r(eturn)    Return out of a subroutine

For more information, use the help command in the debugger, or take a look at ipdb’s online documentation.

Potrei cominciare con i ricordi sulle lotte con i debugger ma poi divento noioso 😡 Invece la vita è bella, dai 😄

:mrgreen:

repl.it – tanti interpreti online

repl-it-logo

Oggi un cinguettio rilanciato da Jeff Martens mi manda da Danzibob che mi dice di repl.it.

Fortuna che non sono invidioso. E poi non faccio roba per il Web. E non conosco JavaScript. E quando uno, due o più sono bravi bisogna dargliene atto. Di Danzibob ho già detto, followatelo, ecco invece quelli di repl.it, followate anche loro. Secondo me, se vi va 😄

team
Ci sono tanti linguaggi, non tutti quelli che vorrei ma OK.
Siccome Python l’ha usato Danzibob io ho riesumato il QuickBasic –no, non lo ricordavo, sono andato per tentativi– e poi l’ho riscritto in Scheme (sì, manca uno spazio, nessuno è perfetto (cit.)).

ri
Non so voi ma io vorrei davvero essere come questi nerd che mi fanno quasi –fortuna che non sono invidioso 😊
:mrgreen: