mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-02-07 09:18:59 +00:00
34 lines
17 KiB
HTML
34 lines
17 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>The overview of a programming environment</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>The overview of a programming environment</h1><section class="post-metadata"><span>Date: <!-- -->2020-06-09 06:21:37 +08:00</span><span>Date modified: <!-- -->2021-05-04 20:52:15 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#the-elements-of-programming" class="toc-link toc-link-h1">The elements of programming</a></li><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#expressions" class="toc-link toc-link-h1">Expressions</a></li><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#namespacing-and-function-composition" class="toc-link toc-link-h1">Namespacing and function composition</a></li><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#conditionals" class="toc-link toc-link-h1">Conditionals</a></li><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#evaluation-model" class="toc-link toc-link-h1">Evaluation model</a></li><li class="toc-item toc-item-h1"><a href="/wiki/2020-06-09-06-21-37#related-resources" class="toc-link toc-link-h1">Related resources</a></li></ol></nav><p>The study of <a href="/wiki/2020-06-03-15-21-42">Computational processes</a> start with the study of a programming environment.
|
|
The programming environment is mostly a given in programming but let's inspect and state some things (and some are obvious) about it.
|
|
</p><h1 id="the-elements-of-programming">The elements of programming</h1><p>A programming language enables you to make the following:
|
|
</p><ul><li><p>Expressions ranging from a primitive value to a complex type.
|
|
</p></li><li><p>A way to combine simple expressions into complex ones.
|
|
</p></li><li><p>A way to abstract procedures into higher-level processes.
|
|
</p></li></ul><h1 id="expressions">Expressions</h1><p>Expressions may be of a primitive value (e.g., <code class="inline-code">265</code>, <code class="inline-code">-1.0</code>, <code class="inline-code">'string</code>) or <strong>combinations</strong> which are composed of operators and expressions (e.g., <code class="inline-code">(+ 2 6)</code>, <code class="inline-code">(* 6 3)</code>).
|
|
An expression can also hold expressions referred to as a subexpression (e.g., <code class="inline-code">(+ (* 5 12) (- 54 6) 9)</code>).
|
|
</p><h1 id="namespacing-and-function-composition">Namespacing and function composition</h1><p>A programming environment should have a way to refer to computational objects.
|
|
These often comes in the form of names with each referring to a value (e.g., <code class="inline-code">(define x 10)</code>).
|
|
</p><p>A programming language should also provide the way to combine simple procedures to compound procedures (e.g., <code class="inline-code">(define (square x) (* x x))</code>) which can be referred to by name (e.g., <code class="inline-code">(square 10)</code> evaluates to <code class="inline-code">100</code>).
|
|
With that said, we can then combine compound procedures to create a procedure of higher level (e.g., <code class="inline-code">(define (sum-of-squares x y) (+ (square x) (square y)))</code>).
|
|
</p><h1 id="conditionals">Conditionals</h1><p>With expressions, environment, and function composition, we can create simple programs.
|
|
However, we cannot create functions that may test for the value (e.g., <a href="wikipedia:Piecewise functions">piecewise functions</a>).
|
|
For this, a way to conditionally evaluate a value is a must for a programming language.
|
|
</p><p>Here's an example function of getting the absolute value of a number.
|
|
</p><pre class="src-block"><code class="language-scheme">(define (abs x)
|
|
(cond
|
|
((< x 0) (- x))
|
|
(else x)))
|
|
</code></pre><h1 id="evaluation-model">Evaluation model</h1><p>Each interpreter implements a different way to evaluate expressions.
|
|
</p><p>One of the simplest evaluation model is the <strong>substitution model</strong> <!-- -->.
|
|
The substitution model works by knowing the meaning of each value and substituting the value with its equivalent.
|
|
</p><h1 id="related-resources">Related resources</h1><ul><li><p><a href="https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-10.html"><em>Structure and interpretation of computer programs</em>, chapter 1</a></p></li></ul></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2020-06-09 06:21:37 +08:00\"","date_modified":"\"2021-05-04 20:52:15 +08:00\"","language":"en","source":""},"title":"The overview of a programming environment","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"the-elements-of-programming"},"children":[{"type":"text","value":"The elements of programming"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#the-elements-of-programming"},"children":[{"type":"text","value":"The elements of programming"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"expressions"},"children":[{"type":"text","value":"Expressions"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#expressions"},"children":[{"type":"text","value":"Expressions"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"namespacing-and-function-composition"},"children":[{"type":"text","value":"Namespacing and function composition"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#namespacing-and-function-composition"},"children":[{"type":"text","value":"Namespacing and function composition"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"conditionals"},"children":[{"type":"text","value":"Conditionals"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#conditionals"},"children":[{"type":"text","value":"Conditionals"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"evaluation-model"},"children":[{"type":"text","value":"Evaluation model"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#evaluation-model"},"children":[{"type":"text","value":"Evaluation model"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"related-resources"},"children":[{"type":"text","value":"Related resources"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/2020-06-09-06-21-37#related-resources"},"children":[{"type":"text","value":"Related resources"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The study of "},{"type":"element","tagName":"a","properties":{"href":"/2020-06-03-15-21-42"},"children":[{"type":"text","value":"Computational processes"}]},{"type":"text","value":" start with the study of a programming environment.\nThe programming environment is mostly a given in programming but let's inspect and state some things (and some are obvious) about it.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"the-elements-of-programming"},"children":[{"type":"text","value":"The elements of programming"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A programming language enables you to make the following:\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Expressions ranging from a primitive value to a complex type.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A way to combine simple expressions into complex ones.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A way to abstract procedures into higher-level processes.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"expressions"},"children":[{"type":"text","value":"Expressions"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Expressions may be of a primitive value (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"265"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"-1.0"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"'string"}]},{"type":"text","value":") or "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"combinations"}]},{"type":"text","value":" which are composed of operators and expressions (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(+ 2 6)"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(* 6 3)"}]},{"type":"text","value":").\nAn expression can also hold expressions referred to as a subexpression (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(+ (* 5 12) (- 54 6) 9)"}]},{"type":"text","value":").\n"}]},{"type":"element","tagName":"h1","properties":{"id":"namespacing-and-function-composition"},"children":[{"type":"text","value":"Namespacing and function composition"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A programming environment should have a way to refer to computational objects.\nThese often comes in the form of names with each referring to a value (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(define x 10)"}]},{"type":"text","value":").\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A programming language should also provide the way to combine simple procedures to compound procedures (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(define (square x) (* x x))"}]},{"type":"text","value":") which can be referred to by name (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(square 10)"}]},{"type":"text","value":" evaluates to "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"100"}]},{"type":"text","value":").\nWith that said, we can then combine compound procedures to create a procedure of higher level (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"(define (sum-of-squares x y) (+ (square x) (square y)))"}]},{"type":"text","value":").\n"}]},{"type":"element","tagName":"h1","properties":{"id":"conditionals"},"children":[{"type":"text","value":"Conditionals"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"With expressions, environment, and function composition, we can create simple programs.\nHowever, we cannot create functions that may test for the value (e.g., "},{"type":"element","tagName":"a","properties":{"href":"wikipedia:Piecewise functions"},"children":[{"type":"text","value":"piecewise functions"}]},{"type":"text","value":").\nFor this, a way to conditionally evaluate a value is a must for a programming language.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's an example function of getting the absolute value of a number.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-scheme"]},"children":[{"type":"text","value":"(define (abs x)\n (cond\n ((\u003c x 0) (- x))\n (else x)))\n"}]}]},{"type":"element","tagName":"h1","properties":{"id":"evaluation-model"},"children":[{"type":"text","value":"Evaluation model"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Each interpreter implements a different way to evaluate expressions.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"One of the simplest evaluation model is the "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"substitution model"}]},{"type":"text","value":" "},{"type":"text","value":".\nThe substitution model works by knowing the meaning of each value and substituting the value with its equivalent.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"related-resources"},"children":[{"type":"text","value":"Related resources"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-10.html"},"children":[{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"Structure and interpretation of computer programs"}]},{"type":"text","value":", chapter 1"}]}]}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["2020-06-09-06-21-37"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |