From 6c2cbb02ac4b16ee7b4c37de50403ce604868ec0 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 8 Apr 2023 16:20:00 -0300 Subject: v2: i18n of the collection name, "article" collection in root --- v2/src/content/pt/hea/condicional-ternario-lisp.md | 65 +++++++++++++ v2/src/content/pt/pastebin/exercicios-sicp-e-19.md | 105 +++++++++++++++++++++ .../content/pt/pastebins/exercicios-sicp-e-19.md | 105 --------------------- v2/src/content/pt/sobre.md | 7 -- v2/src/content/pt/sobre.page | 7 ++ 5 files changed, 177 insertions(+), 112 deletions(-) create mode 100644 v2/src/content/pt/hea/condicional-ternario-lisp.md create mode 100644 v2/src/content/pt/pastebin/exercicios-sicp-e-19.md delete mode 100644 v2/src/content/pt/pastebins/exercicios-sicp-e-19.md delete mode 100644 v2/src/content/pt/sobre.md create mode 100644 v2/src/content/pt/sobre.page (limited to 'v2/src/content/pt') diff --git a/v2/src/content/pt/hea/condicional-ternario-lisp.md b/v2/src/content/pt/hea/condicional-ternario-lisp.md new file mode 100644 index 0000000..6971827 --- /dev/null +++ b/v2/src/content/pt/hea/condicional-ternario-lisp.md @@ -0,0 +1,65 @@ +--- + +title: Three-way conditional for number signs on Lisp + +date: 2021-04-24 3 + +update: 2021-08-14 + +categories: lisp scheme common-lisp + +--- + +A useful macro from Paul Graham's [On Lisp][on-lisp] book: + +```lisp +(defmacro nif (expr pos zero neg) + (let ((g (gensym))) + `(let ((,g ,expr)) + (cond ((plusp ,g) ,pos) + ((zerop ,g) ,zero) + (t ,neg))))) +``` + +After I looked at this macro, I started seeing opportunities to using it in +many places, and yet I didn't see anyone else using it. + +The latest example I can think of is section 1.3.3 of [Structure and +Interpretation of Computer Programs][sicp], which I was reading recently: + +```scheme +(define (search f neg-point pos-point) + (let ((midpoint (average neg-point pos-point))) + (if (close-enough? neg-point post-point) + midpoint + (let ((test-value (f midpoint))) + (cond ((positive? test-value) + (search f neg-point midpoint)) + ((negative? test-value) + (search f midpoint pos-point)) + (else midpoint)))))) +``` + +Not that the book should introduce such macro this early, but I couldn't +avoid feeling bothered by not using the `nif` macro, which could even remove +the need for the intermediate `test-value` variable: + +```scheme +(define (search f neg-point pos-point) + (let ((midpoint (average neg-point pos-point))) + (if (close-enough? neg-point post-point) + midpoint + (nif (f midpoint) + (search f neg-point midpoint) + (midpoint) + (search f midpoint pos-point))))) +``` + +It also avoids `cond`'s extra clunky parentheses for grouping, which is +unnecessary but built-in. + +As a macro, I personally feel it tilts the balance towards expressivenes +despite its extra cognitive load toll. + +[on-lisp]: http://www.paulgraham.com/onlisptext.html [sicp]: +https://mitpress.mit.edu/sites/default/files/sicp/index.html diff --git a/v2/src/content/pt/pastebin/exercicios-sicp-e-19.md b/v2/src/content/pt/pastebin/exercicios-sicp-e-19.md new file mode 100644 index 0000000..89dacfd --- /dev/null +++ b/v2/src/content/pt/pastebin/exercicios-sicp-e-19.md @@ -0,0 +1,105 @@ +--- + +title: SICP exercise 3.19 + +date: 2021-09-02 + +categories: lisp programming-languages + +--- + +Some content here, before: + +```scheme +(define (cycle? l) + (define (rec l x) + (cond + ((null? x) false) + ((eq? l x) true) + (true (rec l (cdr x))))) + (rec l (cdr l))) +``` + +Sample interactive session: + +```scheme +scheme@(guile-user)> (define true #t) +scheme@(guile-user)> (define false #f) +scheme@(guile-user)> +(define (cycle? l) + (define (rec l x) + (cond + ((null? x) false) + ((eq? l x) true) + (true (rec l (cdr x))))) + (rec l (cdr l))) +scheme@(guile-user)> (cycle? '(1 2 3)) +$9 = #f +scheme@(guile-user)> (cycle? (make-cycle '(1 2 3))) +$10 = #t +``` + +# An h1 + +a list: + +1. one +2. two +3. three + +some content. + +- item +- another +- yet another + +## An h2 + +Xablau: + +``` xupliu 1 + +3 4 + + + + + +dez ``` + +Foi `wikiwiu`. + +a very long code block: + +``` +wef +wef wef wef wef +wef wef wef wef we fwef wef wef wef wef +``` + +Someone said: + +> Xablau, xupliu. + +### A repeated header ### A repeated header + +a big list: + +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a +1. a diff --git a/v2/src/content/pt/pastebins/exercicios-sicp-e-19.md b/v2/src/content/pt/pastebins/exercicios-sicp-e-19.md deleted file mode 100644 index 89dacfd..0000000 --- a/v2/src/content/pt/pastebins/exercicios-sicp-e-19.md +++ /dev/null @@ -1,105 +0,0 @@ ---- - -title: SICP exercise 3.19 - -date: 2021-09-02 - -categories: lisp programming-languages - ---- - -Some content here, before: - -```scheme -(define (cycle? l) - (define (rec l x) - (cond - ((null? x) false) - ((eq? l x) true) - (true (rec l (cdr x))))) - (rec l (cdr l))) -``` - -Sample interactive session: - -```scheme -scheme@(guile-user)> (define true #t) -scheme@(guile-user)> (define false #f) -scheme@(guile-user)> -(define (cycle? l) - (define (rec l x) - (cond - ((null? x) false) - ((eq? l x) true) - (true (rec l (cdr x))))) - (rec l (cdr l))) -scheme@(guile-user)> (cycle? '(1 2 3)) -$9 = #f -scheme@(guile-user)> (cycle? (make-cycle '(1 2 3))) -$10 = #t -``` - -# An h1 - -a list: - -1. one -2. two -3. three - -some content. - -- item -- another -- yet another - -## An h2 - -Xablau: - -``` xupliu 1 - -3 4 - - - - - -dez ``` - -Foi `wikiwiu`. - -a very long code block: - -``` -wef -wef wef wef wef -wef wef wef wef we fwef wef wef wef wef -``` - -Someone said: - -> Xablau, xupliu. - -### A repeated header ### A repeated header - -a big list: - -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a -1. a diff --git a/v2/src/content/pt/sobre.md b/v2/src/content/pt/sobre.md deleted file mode 100644 index aac3e67..0000000 --- a/v2/src/content/pt/sobre.md +++ /dev/null @@ -1,7 +0,0 @@ ---- - -title: About - ---- - -It's all about me, baby! diff --git a/v2/src/content/pt/sobre.page b/v2/src/content/pt/sobre.page new file mode 100644 index 0000000..aac3e67 --- /dev/null +++ b/v2/src/content/pt/sobre.page @@ -0,0 +1,7 @@ +--- + +title: About + +--- + +It's all about me, baby! -- cgit v1.2.3