Lisp

{"content":{"id":1058,"title":"'Build Your Own Lisp' Solutions: 6.6","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Change the grammar to recognize decimal numbers such as 0.01, 5.21, or 10.2.\u003c/p\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e\" \\\r\nnumber : /-?[0-9]+(.[0-9]+)*/ ; \\\r\noperator : 'add' | 'sub' | 'mul' | 'div'; \\\r\nexpr : \u0026lt;number\u003e | '(' \u0026lt;operator\u003e \u0026lt;expr\u003e+ ')' ; \\\r\nlispy : /^/ \u0026lt;operator\u003e \u0026lt;expr\u003e+ /$/ ; \\\r\n\"\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2020-01-04T00:00:00.000Z","created_at":"2019-12-10T00:09:33.000Z","updated_at":"2020-07-06T19:13:57.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.6

Q: Change the grammar to recognize decimal numbers such as 0.01, 5.21, or 10.2.

A:

"                                                   \
number   : /-?[0-9]+(.[0-9]+)*/ ;                   \
operator : 'add' | 'sub' | 'mul' | 'div';           \
expr     : <number> | '(' <operator> <expr>+ ')' ;  \
lispy    : /^/ <operator> <expr>+ /$/ ;             \
"

{"content":{"id":1023,"title":"'Build Your Own Lisp' Solutions: 6.5","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e › Change the grammar to recognise operators written in textual format 'add', 'sub', 'mul', 'div'.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e\" \\\r\nnumber : /-?[0-9]+/ ; \\\r\noperator : 'add' | 'sub' | 'mul' | 'div'; \\\r\nexpr : \u0026lt;number\u003e | '(' \u0026lt;operator\u003e \u0026lt;expr\u003e+ ')' ; \\\r\nlispy : /^/ \u0026lt;operator\u003e \u0026lt;expr\u003e+ /$/ ; \\\r\n\"\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-12-04T00:00:00.000Z","created_at":"2019-11-04T20:51:40.000Z","updated_at":"2019-11-04T21:00:09.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.5

Q: › Change the grammar to recognise operators written in textual format 'add', 'sub', 'mul', 'div'.


A:

"                                                   \
number   : /-?[0-9]+/ ;                             \
operator : 'add' | 'sub' | 'mul' | 'div';           \
expr     : <number> | '(' <operator> <expr>+ ')' ;  \
lispy    : /^/ <operator> <expr>+ /$/ ;             \
"

{"content":{"id":1015,"title":"'Build Your Own Lisp' Solutions: 6.4","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Change the grammar to add a new operator such as '%'.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e\" \\\r\nnumber : /-?[0-9]+/ ; \\\r\noperator : '+' | '-' | '*' | '/' | '%'; \\\r\nexpr : \u0026lt;number\u003e | '(' \u0026lt;operator\u003e \u0026lt;expr\u003e+ ')' ; \\\r\nlispy : /^/ \u0026lt;operator\u003e \u0026lt;expr\u003e+ /$/ ; \\\r\n\"\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-11-27T00:00:00.000Z","created_at":"2019-10-28T19:56:26.000Z","updated_at":"2019-10-28T20:03:09.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.4

Q: Change the grammar to add a new operator such as '%'.


A:

"                                                   \
number   : /-?[0-9]+/ ;                             \
operator : '+' | '-' | '*' | '/' | '%';             \
expr     : <number> | '(' <operator> <expr>+ ')' ;  \
lispy    : /^/ <operator> <expr>+ /$/ ;             \
"

{"content":{"id":982,"title":"'Build Your Own Lisp' Solutions: 6.3","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Write a regular expression matching pit, pot and respite but not peat, spit, or part.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e# This works, but is a weird answer to a weird exercise.\r\n/(^|res)p[io]/\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-11-13T00:00:00.000Z","created_at":"2019-10-16T01:07:00.000Z","updated_at":"2019-10-16T01:12:33.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.3

Q: Write a regular expression matching pit, pot and respite but not peat, spit, or part.


A:

# This works, but is a weird answer to a weird exercise.
/(^|res)p[io]/

{"content":{"id":927,"title":"'Build Your Own Lisp' Solutions: 6.2","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Write a regular expression matching strings of consecutive a and b such as ababab or aba.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e/(ab)/\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-10-09T00:00:00.000Z","created_at":"2019-09-08T19:17:57.000Z","updated_at":"2019-09-08T19:17:57.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.2

Q: Write a regular expression matching strings of consecutive a and b such as ababab or aba.


A:

/(ab)/

{"content":{"id":871,"title":"'Build Your Own Lisp' Solutions: 6.1","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Write a regular expression matching strings of all a or b such as aababa or bbaa.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e/^(a|b)+$/\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-09-05T00:00:00.000Z","created_at":"2019-08-06T21:35:19.000Z","updated_at":"2019-08-06T21:38:40.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 6.1

Q: Write a regular expression matching strings of all a or b such as aababa or bbaa.


A:

/^(a|b)+$/

{"content":{"id":806,"title":"'Build Your Own Lisp' Solutions: 5.4","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Describe textually a grammar for decimal numbers such as \u003ci\u003e0.01\u003c/i\u003e or \u003ci\u003e52.221\u003c/i\u003e.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e// Using the same system he's given us to describe decimals:\r\n\" \\\r\n digit : \\\"0\\\" | \\\"1\\\" \\\"2\\\" | \\\"3\\\" \\\"4\\\" \\\r\n | \\\"5\\\" | \\\"6\\\" \\\"7\\\" | \\\"8\\\" \\\"9\\\"; \\\r\n number : \u0026lt;digit\u0026gt;+; \\\r\n decimal : \u0026lt;number\u0026gt;+\\.\u0026lt;number\u0026gt;+; \\\r\n\"\r\n/* The URL example is essentially the same, but with a all the letters \r\n * of the alphabet. The rest of the questions in the chapter are soft\r\n * enough to be left to the interested reader. */\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-07-26T00:00:00.000Z","created_at":"2019-06-28T18:09:04.000Z","updated_at":"2019-06-29T20:42:50.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 5.4

Q: Describe textually a grammar for decimal numbers such as 0.01 or 52.221.


A:

// Using the same system he's given us to describe decimals:
"                                             \
 digit   : \"0\" | \"1\" \"2\" | \"3\" \"4\"  \
         | \"5\" | \"6\" \"7\" | \"8\" \"9\"; \
 number  : <digit>+;                          \
 decimal : <number>+\.<number>+;              \
"
/* The URL example is essentially the same, but with a all the letters 
 * of the alphabet. The rest of the  questions in the chapter are soft
 * enough to be left to the interested reader. */

{"content":{"id":807,"title":"Weekly Links - Second Death Of Latin Edition","body":"\u003cul\u003e\r\n\u003cli\u003e\r\nRadio Finland has been running a \u003ca href=\"https://areena.yle.fi/1-1931339\"\u003eLatin news service\u003c/a\u003e for 30 years. In Canada, they used to play it as about two or three in the morning. It was very neutral world news, with a charmingly disproportional amount of Finnish politics. They'd been threatening to cancel it for years and finally it happened. Some people are trying to \u003ca href=\"https://nuntiilatini.com/\"\u003econtinue it in their free time\u003c/a\u003e and I wish them the best of luck.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nI quit watching SNL in the Jimmy Fallon years, for obvious reasons. Now I'm finding out that - thanks to Jimmy Fallon - I missed out on all kinds of great gems, like \u003ca href=\"https://youtu.be/MJEAGd1bQuc\"\u003eMeet Your Second Wife\u003c/a\u003e.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nThe standard C library has a simple reversible encryption function called \u003ca href=\"https://linux.die.net/man/3/memfrob\"\u003ememfrob\u003c/a\u003e which XORs a string with 42.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nSomeone went through the effort of writing \u003ca href=\"https://github.com/froggey/Mezzano/\"\u003ea graphical operating system in Common LISP\u003c/a\u003e. Can you imagine doing that?\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\n\u003ca href=\"https://shkspr.mobi/blog/2019/06/the-worst-morale-boosting-gesture-ive-experienced/\"\u003e\"The worst morale boosting gesture I've experienced\"\u003c/a\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nThere's a gigantic culture of programmers with whom I have no contact whatsoever. I don't understand their lives, which seem gruesome and difficult and cursed, even though they seem endlessly optimistic and perfectly happy. It's like when you find out that a lot of poverty-torn developing countries have low suicide rates. In DOTNET, \u003ca href=\"https://github.com/dotnet/try/issues/290\"\u003eMath.Round opens the browser print dialog\u003c/a\u003e.\r\n\u003c/li\u003e\r\n\u003c/ul\u003e","publication_date":"2019-06-30T00:00:00.000Z","created_at":"2019-06-29T17:27:28.000Z","updated_at":"2019-06-29T17:45:45.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=weekly_links\"\u003eweekly_links\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=latin\"\u003elatin\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=finland\"\u003efinland\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=comedy\"\u003ecomedy\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=douglas_adams\"\u003edouglas_adams\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=common_lisp\"\u003ecommon_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=hype\"\u003ehype\u003c/a\u003e"}

Weekly Links - Second Death Of Latin Edition

  • Radio Finland has been running a Latin news service for 30 years. In Canada, they used to play it as about two or three in the morning. It was very neutral world news, with a charmingly disproportional amount of Finnish politics. They'd been threatening to cancel it for years and finally it happened. Some people are trying to continue it in their free time and I wish them the best of luck.
  • I quit watching SNL in the Jimmy Fallon years, for obvious reasons. Now I'm finding out that - thanks to Jimmy Fallon - I missed out on all kinds of great gems, like Meet Your Second Wife.
  • The standard C library has a simple reversible encryption function called memfrob which XORs a string with 42.
  • Someone went through the effort of writing a graphical operating system in Common LISP. Can you imagine doing that?
  • "The worst morale boosting gesture I've experienced"
  • There's a gigantic culture of programmers with whom I have no contact whatsoever. I don't understand their lives, which seem gruesome and difficult and cursed, even though they seem endlessly optimistic and perfectly happy. It's like when you find out that a lot of poverty-torn developing countries have low suicide rates. In DOTNET, Math.Round opens the browser print dialog.
{"content":{"id":722,"title":"'Build Your Own Lisp' Solutions: 5.3","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Why are there back slashes \u003ci\u003e\\\u003c/i\u003e at the end of the line in the grammar?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e C will ignore a combination of a newline followed by \u003ci\u003e\\\u003c/i\u003e, which lets you format long strings more nicely. An example:\r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e#include \u0026ltstdio.h\u0026gt\r\n\r\nint main(void)\r\n{\r\n /* If you count the spaces here and in the resulting output, there are\r\n * 11. The \\ and the newline are dropped. */\r\n printf(\"this is line one \\\r\n and this is line two\\n\");\r\n\r\n return 0;\r\n}\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003cpre\u003e\u003ccode class=\"lisp\"\u003ethis is line one and this is line two\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e\r\n\u003c!--\r\n\u003cstyle\u003e\r\ni { background: white; font-style: normal; margin-left: 3px; margin-right: 3px }\r\n\u003c/style\u003e\r\n--\u003e","publication_date":"2019-06-20T00:00:00.000Z","created_at":"2019-05-19T18:52:47.000Z","updated_at":"2019-06-22T02:53:03.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 5.3

Q: Why are there back slashes \ at the end of the line in the grammar?


A: C will ignore a combination of a newline followed by \, which lets you format long strings more nicely. An example:

#include <stdio.h>

int main(void)
{
  /* If you count the spaces here and in the resulting output, there are
   * 11. The \ and the newline are dropped. */
  printf("this is line one \
          and this is line two\n");

  return 0;
}
this is line one           and this is line two

{"content":{"id":721,"title":"'Build Your Own Lisp' Solutions: 5.2","body":"\u003cdiv class=\"card-image-caption\"\u003e(5.1 is a fun exercise and left to the reader)\u003c/div\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Why are there back slashes \u003ci\u003e\\\u003c/i\u003e in front of the quote marks \u003ci\u003e\"\u003c/i\u003e in the grammar?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e So the C compiler doesn't mistake them for quotation marks which end the string.\r\n\u003c/p\u003e\r\n\u003c!--\r\n\u003cstyle\u003e\r\ni { background: white; font-style: normal; margin-left: 3px; margin-right: 3px }\r\n\u003c/style\u003e\r\n--\u003e","publication_date":"2019-06-19T00:00:00.000Z","created_at":"2019-05-19T16:50:55.000Z","updated_at":"2019-06-22T02:53:32.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 5.2

(5.1 is a fun exercise and left to the reader)

Q: Why are there back slashes \ in front of the quote marks " in the grammar?


A: So the C compiler doesn't mistake them for quotation marks which end the string.

{"content":{"id":705,"title":"'Build Your Own Lisp' Solutions: 4.9","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e If \u003ci\u003e_WIN32\u003c/i\u003e is defined on windows, what is defined for Linux or Mac?\u003c/p\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \u003ci\u003e__linux__\u003c/i\u003e, and \u003ci\u003e__APPLE__\u003c/i\u003e, not to mention \u003ci\u003e__ANDROID__\u003c/i\u003e (which is a type of \u003ci\u003e__linux__\u003c/i\u003e, so something like \u003ci\u003e__linux__ \u0026\u0026 !__ANDROID__\u003c/i\u003e is possible).\u003c/p\u003e\r\n\u003cstyle\u003e\r\ni { background: white; font-style: normal; margin-left: 3px; margin-right: 3px }\r\n\u003c/style\u003e","publication_date":"2019-06-08T00:00:00.000Z","created_at":"2019-05-09T21:47:37.000Z","updated_at":"2020-07-06T03:21:32.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 4.9

Q: If _WIN32 is defined on windows, what is defined for Linux or Mac?

A: __linux__, and __APPLE__, not to mention __ANDROID__ (which is a type of __linux__, so something like __linux__ && !__ANDROID__ is possible).

{"content":{"id":688,"title":"'Build Your Own Lisp' Solutions: 4.8","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e What does the preprocessor command \u003ci\u003e#define\u003c/i\u003e do?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e It creates a macro, which is to say, it let's you associate a word with an expression. Before compiling your code, the precompiler will replace every instance of that word with that expression. While most macros you see are quite simple, you can do pretty amazing things with them. See \u003ca href=\"https://gcc.gnu.org/onlinedocs/cpp/Macros.html\"\u003ehere\u003c/a\u003e for a detailed reference.\u003c/p\u003e","publication_date":"2019-06-04T00:00:00.000Z","created_at":"2019-05-04T20:21:30.000Z","updated_at":"2019-05-09T21:41:13.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 4.8

Q: What does the preprocessor command #define do?


A: It creates a macro, which is to say, it let's you associate a word with an expression. Before compiling your code, the precompiler will replace every instance of that word with that expression. While most macros you see are quite simple, you can do pretty amazing things with them. See here for a detailed reference.

{"content":{"id":684,"title":"'Build Your Own Lisp' Solutions: 4.7","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e What does the preprocessor command \u003ci\u003e#ifndef\u003c/i\u003e do?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e Checks if a token has already been defined earlier in the file, or in a previous file, then includes anything between it and \u003ci\u003e#else\u003c/i\u003e or \u003ci\u003e#endif\u003c/i\u003e.\u003c/p\u003e","publication_date":"2019-06-01T00:00:00.000Z","created_at":"2019-05-01T18:38:12.000Z","updated_at":"2019-06-01T02:44:45.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 4.7

Q: What does the preprocessor command #ifndef do?


A: Checks if a token has already been defined earlier in the file, or in a previous file, then includes anything between it and #else or #endif.

{"content":{"id":681,"title":"'Build Your Own Lisp' Solutions: 4.6","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e What happens when you pass \u003ci\u003eprintf\u003c/i\u003e a variable that does not match the pattern?\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e\u003c/p\u003e\r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e#include \u0026ltstdio.h\u0026gt\r\n\r\nint main(void)\r\n{\r\n // This depends heavily on the kind of mistake you want to make. Some \r\n // examples:\r\n\r\n // A character is really a number, so this is fine.\r\n printf(\"%c\\n\", 109);\r\n // And vice-versa.\r\n printf(\"%d\\n\", 'm');\r\n // A string really just points to the memory address of the first character,\r\n // and %d will try to interpret that address as a base ten number, so this\r\n // will be something different every time you run the program.\r\n printf(\"%d\\n\", \"moo\");\r\n\r\n // These examples all happen to give you something, but the compiler has no \r\n // idea what to do with something like 'printf(\"%s\\n\", 13);', and will give \r\n // you a Segment Fault error.\r\n\r\n return 0;\r\n}\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003cpre\u003e\u003ccode class=\"lisp\"\u003e\u0026gt ./wrong \r\nm\r\n109\r\n340750348\r\n\u003c/code\u003e\u003c/pre\u003e","publication_date":"2019-05-31T00:00:00.000Z","created_at":"2019-04-30T01:26:32.000Z","updated_at":"2019-05-01T18:38:09.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 4.6

Q: What happens when you pass printf a variable that does not match the pattern?

A:

#include <stdio.h>

int main(void)
{
  // This depends heavily on the kind of mistake you want to make. Some 
  // examples:

  // A character is really a number, so this is fine.
  printf("%c\n", 109);
  // And vice-versa.
  printf("%d\n", 'm');
  // A string really just points to the memory address of the first character,
  // and %d will try to interpret that address as a base ten number, so this
  // will be something different every time you run the program.
  printf("%d\n", "moo");

  // These examples all happen to give you something, but the compiler has no 
  // idea what to do with something like 'printf("%s\n", 13);', and will give 
  // you a Segment Fault error.

  return 0;
}
> ./wrong 
m
109
340750348
{"content":{"id":641,"title":"'Build Your Own Lisp' Solutions: 4.5","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e What other patterns can be used with printf?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e More than are worth memorizing (at least all at once). As the chapter states, it's best to \u003ca href=\"http://www.cplusplus.com/reference/cstdio/printf/\"\u003echeck a good reference\u003c/a\u003e.\u003c/p\u003e","publication_date":"2019-05-09T00:00:00.000Z","created_at":"2019-04-08T22:00:49.000Z","updated_at":"2019-04-08T22:01:24.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 4.5

Q: What other patterns can be used with printf?


A: More than are worth memorizing (at least all at once). As the chapter states, it's best to check a good reference.

{"content":{"id":655,"title":"19-04-21 Weekly Links","body":"\u003cul\u003e\r\n\u003cli\u003e\r\nFeeling down? Listen to an hour of \u003ca href=\"http://traffic.libsyn.com/pft/Tompkast_-_Chapter_14_-_Abbie_Hoffman.mp3\"\u003eJen Kirkman improvising as Abbie Hoffman\u003c/a\u003e.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nWikipedia's \u003ca href=\"https://en.wikipedia.org/wiki/List_of_unusual_deaths\"\u003elist of unusual deaths\u003c/a\u003e is hypnotic to read, although the entries for the last few years are badly-maintained.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nSomeone went through a lot of effort to nicely format the public domain classic \u003ca href=\"http://calculusmadeeasy.org/\"\u003eCalculus Made Easy\u003c/a\u003e for the web. \r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nThe creator of Erlang recently passed away. Once he wrote an excellent thing on \u003ca href=\"https://elixirforum.com/t/learning-elixir-frst-impressions-plz-dont-kill-me/16424/52\"\u003eElixir and OOP in general\u003c/a\u003e.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nTwitter must have been down for ten minutes, because BBC News ran a story which is not only not about tweets, but which is not 85% Twitter commentary. \u003ca href=\"https://www.bbc.com/news/uk-scotland-47953541\"\u003eDeaths after surgery in Scotland have dropped by more than a third after implementing a checklist\u003c/a\u003e. I once had a boss yell at me for making checklists, as he felt memorizing constantly-changing daily tasks was some kind of macho thing, and making lists was effeminate. He was not as smart as a surgeon.\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\nThey just released the source for a bunch of old Infocom games, including \u003ca href=\"https://github.com/historicalsource/zork1-gold\"\u003ethe early Zorks\u003c/a\u003e, all written in an old LISP dialect, whose manual you can read \u003ca href=\"https://archive.org/details/Learning_ZIL_Steven_Eric_Meretzky_1995\"\u003ehere\u003c/a\u003e. Take a second to let that all sink in. Sample data:\r\n\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cpre\u003e\u003ccode\u003e\u0026lt;OBJECT SANDWICH-BAG\r\n\t(LOC KITCHEN-TABLE)\r\n\t(SYNONYM BAG SACK)\r\n\t(ADJECTIVE BROWN ELONGATED SMELLY)\r\n\t(DESC \"brown sack\")\r\n\t(FLAGS TAKEBIT CONTBIT BURNBIT)\r\n\t(FDESC\r\n\"On the table is an elongated brown sack, smelling of hot peppers.\")\r\n\t(CAPACITY 9)\r\n\t(SIZE 9)\r\n\u0026gt;\r\n\u003c/code\u003e\u003c/pre\u003e","publication_date":"2019-04-21T00:00:00.000Z","created_at":"2019-04-20T16:13:35.000Z","updated_at":"2019-04-23T02:43:17.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=weekly_links\"\u003eweekly_links\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=comedy\"\u003ecomedy\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=death\"\u003edeath\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=mathematics\"\u003emathematics\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=books\"\u003ebooks\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=computers_science\"\u003ecomputers_science\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=zork\"\u003ezork\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=video_games\"\u003evideo_games\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=erlang\"\u003eerlang\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=the_wicked_elixir\"\u003ethe_wicked_elixir\u003c/a\u003e"}

19-04-21 Weekly Links

<OBJECT SANDWICH-BAG
	(LOC KITCHEN-TABLE)
	(SYNONYM BAG SACK)
	(ADJECTIVE BROWN ELONGATED SMELLY)
	(DESC "brown sack")
	(FLAGS TAKEBIT CONTBIT BURNBIT)
	(FDESC
"On the table is an elongated brown sack, smelling of hot peppers.")
	(CAPACITY 9)
	(SIZE 9)
>