{"id":23725,"date":"2023-05-09T03:24:34","date_gmt":"2023-05-09T03:24:34","guid":{"rendered":"https:\/\/www.booksofall.com\/es\/?post_type=product&#038;p=23725"},"modified":"2023-05-09T03:24:35","modified_gmt":"2023-05-09T03:24:35","slug":"programming-languages-application-and-interpretation-2","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/","title":{"rendered":"Programming Languages: Application and Interpretation"},"content":{"rendered":"<h2>2 Everything (We Will Say) About Parsing<\/h2>\n<p>Parsing is the act of turning an input character stream into a more structured, internal representation. A common internal representation is as a tree, which programs can<a href=\"https:\/\/users.cs.utah.edu\/~germain\/PPS\/Topics\/recursion.html\"> recursively process<\/a>. For instance, given the stream<br \/>\n23 + 5 &#8211; 6<br \/>\nwe might want a tree representing addition whose left node represents the number 23 and whose right node represents subtraction of 6 from 5. A parser is responsible for performing this transformation.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Parsing\">Parsing<\/a> is a large, complex problem that is far from solved due to the difficulties of ambiguity. For instance, an alternate <a href=\"https:\/\/en.wikipedia.org\/wiki\/Parse_tree\">parse tree<\/a> for the above input expression might put subtraction at the top and addition below it. We might also want to consider whether this addition operation is commutative and hence whether the order of arguments can be switched. Everything only gets much, much worse when we get to full-fledged <a href=\"https:\/\/www.simplilearn.com\/best-programming-languages-start-learning-today-article\">programming languages<\/a> (to say nothing of natural languages).<\/p>\n<h3>2.1 A Lightweight, Built-In First Half of a Parser<\/h3>\n<p>These problems make parsing a worthy topic in its own right, and entire books, tools, and courses are devoted to it. However, from our perspective parsing is mostly a distraction, because we want to study the parts of programming languages that are not parsing. We will therefore exploit a handy feature of Racket to manage the transformation of input streams into trees: read. read is tied to the parenthetical form of the language, in that it parses fully (and hence unambiguously) parenthesized terms into a built-in tree form. For instance, running (read) on the parenthesized form of the above input\u2014<br \/>\n(+ 23 (- 5 6))<br \/>\n\u2014will produce a list, whose first element is the symbol \u2019+, second element is the number 23, and third element is a list; this list\u2019s first element is the symbol \u2019-, second element is the number 5, and third element is the number 6.<\/p>\n<h3>2.2 A Convenient Shortcut<\/h3>\n<p>As you know you need to test your programs extensively, which is hard to do when you must manually type terms in over and over again. Fortunately, as you might expect, the parenthetical syntax is integrated deeply into <a href=\"https:\/\/racket-lang.org\/\">Racket<\/a> through the mechanism of quotation. That is, \u2019&lt;expr&gt;\u2014which you saw a moment ago in the above example\u2014acts as if you had run (read) and typed &lt;expr&gt; at the prompt (and, of course, evaluates to the value the (read) would have).<\/p>\n<h3>2.3 Types for Parsing<\/h3>\n<p>Actually, I\u2019ve lied a little. I said that (read)\u2014or equivalently, using quotation\u2014will produce a list, etc. That\u2019s true in regular Racket, but in Typed PLAI, the type it returns a distinct type called an s-expression, written in Typed PLAI as <a href=\"https:\/\/en.wikipedia.org\/wiki\/S-expression\">s-expression<\/a>:<br \/>\n&gt; (read)<br \/>\n&#8211; s-expression<br \/>\n[type in (+ 23 (- 5 6))]<br \/>\n&#8216;(+ 23 (- 5 6))<br \/>\nRacket has a very rich language of s-expressions (it even has notation to represent cyclic structures), but we will use only the simple fragment of it.<\/p>\n<p>In the typed language, an s-expression is treated distinctly from the other types, such as numbers and lists. Underneath, an s-expression is a large recursive datatype that consists of all the base printable values\u2014numbers, strings, symbols, and so on\u2014and printable collections (lists, <a href=\"https:\/\/www.mathsisfun.com\/algebra\/vectors.html\">vectors<\/a>, etc.) of s-expressions. As a result, base types like numbers, symbols, and strings are both their own type and an instance of s-expression. Typing such data can be fairly problematic, as we will discuss later [REF].<\/p>\n<p>Typed PLAI takes a simple approach. When written on their own, values like numbers are of those respective types. But when written inside a complex s-expression\u2014in particular, as created by read or quotation\u2014they have type s-expression. You have to then cast them to their native types. For instance:<br \/>\n&gt; &#8216;+<br \/>\n&#8211; symbol<br \/>\n&#8216;+<br \/>\n&gt; (define l<br \/>\n&#8216;(+ 1 2)) &gt; l<br \/>\n&#8211; s-expression<br \/>\n&#8216;(+ 1 2) &gt; (first l)<br \/>\n. typecheck failed: (listof &#8216;_a) vs s-expression in:<br \/>\nfirst (quote<br \/>\n(+ 1 2))<br \/>\nl<br \/>\nfirst<br \/>\n&gt; (define f (first (s-exp-&gt;list l)))<br \/>\n&gt; f<br \/>\n&#8211; s-expression<br \/>\n&#8216;+<\/p>\n<p>This is similar to the casting that a Java programmer would have to insert. We will study casting itself later [REF].<\/p>\n<p>Observe that the first element of the list is still not treated by the type checker as a symbol: a list-shaped s-expression is a list of s-expressions. Thus,<br \/>\n&gt; (symbol-&gt;string f)<br \/>\n. typecheck failed:<br \/>\nsymbol vs s-expression in:<br \/>\nsymbol-&gt;string<br \/>\nf<br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">first<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">(first (s-exp-&gt;list l))<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">s-exp-&gt;list<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">whereas again, casting does the trick:<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">&gt; (symbol-&gt;string (s-exp-&gt;symbol f))<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">&#8211; string<br \/>\n&#8220;+&#8221;<\/span><\/p>\n<p>The need to cast s-expressions is a bit of a nuisance, but some complexity is unavoidable because of what we\u2019re trying to accomplish: to convert an untyped input stream into a typed output stream through robustly typed means. Somehow we have to make explicit our assumptions about that input stream.<\/p>\n<p>Fortunately we will use s-expressions only in our parser, and our goal is to get away from parsing as quickly as possible! Indeed, if anything this should be inducement to get away even quicker.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/programming-languages-application-and-interpretation-1clkjnwdgy?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":23729,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!"},"product_brand":[],"product_cat":[385],"product_tag":[],"class_list":{"0":"post-23725","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-theoretical-computer-science","8":"first","9":"instock","10":"shipping-taxable","11":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Programming Languages: Application and Interpretation - BooksOfAll Spanish<\/title>\n<meta name=\"description\" content=\"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programming Languages: Application and Interpretation - BooksOfAll Spanish\" \/>\n<meta property=\"og:description\" content=\"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Spanish\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-09T03:24:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/\",\"url\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/\",\"name\":\"Programming Languages: Application and Interpretation - BooksOfAll Spanish\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg\",\"datePublished\":\"2023-05-09T03:24:34+00:00\",\"dateModified\":\"2023-05-09T03:24:35+00:00\",\"description\":\"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg\",\"width\":\"827\",\"height\":\"1169\",\"caption\":\"Programming Languages: Application and Interpretation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/es\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Programming Languages: Application and Interpretation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#website\",\"url\":\"https:\/\/www.booksofall.com\/es\/\",\"name\":\"BooksOfAll Spanish\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/es\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#organization\",\"name\":\"BooksOfAll Spanish\",\"url\":\"https:\/\/www.booksofall.com\/es\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Spanish\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Programming Languages: Application and Interpretation - BooksOfAll Spanish","description":"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/","og_locale":"es_ES","og_type":"article","og_title":"Programming Languages: Application and Interpretation - BooksOfAll Spanish","og_description":"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!","og_url":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/","og_site_name":"BooksOfAll Spanish","article_modified_time":"2023-05-09T03:24:35+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg","twitter_misc":{"Tiempo de lectura":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/","url":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/","name":"Programming Languages: Application and Interpretation - BooksOfAll Spanish","isPartOf":{"@id":"https:\/\/www.booksofall.com\/es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg","datePublished":"2023-05-09T03:24:34+00:00","dateModified":"2023-05-09T03:24:35+00:00","description":"Programming languages are a vast and complex subject, including many fundamental concepts and advanced techniques . Start your learning with this book now!","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#primaryimage","url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg","contentUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2023\/05\/Programming-Languages-Application-and-Interpretation-1.jpg","width":"827","height":"1169","caption":"Programming Languages: Application and Interpretation"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/es\/programming-languages-application-and-interpretation-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/es\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/es\/categories\/"},{"@type":"ListItem","position":3,"name":"Programming Languages: Application and Interpretation"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/es\/#website","url":"https:\/\/www.booksofall.com\/es\/","name":"BooksOfAll Spanish","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/es\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/es\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/es\/#organization","name":"BooksOfAll Spanish","url":"https:\/\/www.booksofall.com\/es\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/es\/wp-content\/uploads\/sites\/5\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Spanish"},"image":{"@id":"https:\/\/www.booksofall.com\/es\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product\/23725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/media\/23729"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/media?parent=23725"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_brand?post=23725"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_cat?post=23725"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/es\/wp-json\/wp\/v2\/product_tag?post=23725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}