位置: IT常识 - 正文

Homoiconicity

编辑:rootadmin
Homoiconicity - Wikipedia, the free encyclopediaHomoiconicity From Wikipedia, the free encyclopedia HomoiconicityFrom Wikipedia, the free encyclopediaJump to:navigation, searchThis article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (April 2012)

推荐整理分享Homoiconicity,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

In computer programming, homoiconicity is a property of some programming languages, in which the primary representation of programs is also a data structure in a primitive type of the language itself, from the Greek words homo meaning the same and icon meaning representation. This makes metaprogramming easier than in a language without this property. To put that another way, homoiconicity is where a program's source code is written as a basic data structure that the programming language knows how to access. For example, imagine a programming language that is particularly good at list manipulation. Now, imagine what would happen if you required programs for that language to be written in the form of lists. The result would be that the program could access its own source code while running, and programmatically reprogram itself on the fly.

Contents

[hide]

1 History2 Use and advantages3 Examples

3.1 Homoiconicity in Lisp3.2 Homoiconicity in Prolog4 See also5 References6 External links[edit] History

The original source is the paper Macro Instruction Extensions of Compiler Languages,[1] according to the early and influential paper TRAC, A Text-Handling Language:[2]

One of the main design goals was that the input script of TRAC (what is typed in by the user) should be identical to the text which guides the internal action of the TRAC processor. In other words, TRAC procedures should be stored in memory as a string of characters exactly as the user typed them at the keyboard. If the TRAC procedures themselves evolve new procedures, these new procedures should also be stated in the same script. The TRAC processor in its action interprets this script as its program. In other words, the TRAC translator program (the processor) effectively converts the computer into a new computer with a new program language -- the TRAC language. At any time, it should be possible to display program or procedural information in the same form as the TRAC processor will act upon it during its execution. It is desirable that the internal character code representation be identical to, or very similar to, the external code representation. In the present TRAC implementation, the internal character representation is based upon ASCII. Because TRAC procedures and text have the same representation inside and outside the processor, the term homoiconic is applicable, from homo meaning the same, and icon meaning representation.

[...]

Following suggestion of McCullough, W. S., based upon terminology due to Peirce, C. S. s McIlroy. M. D., "Macro Instruction Extensions of Compiler Languages," Comm. ACM, p. 214-220; April, 1960.

Alan Kay used and possibly popularized the term "homoiconic" through his use of the term in his 1969 PhD thesis:[3]

A notable group of exceptions to all the previous systems are Interactive LISP [...] and TRAC. Both are functionally oriented (one list, the other string), both talk to the user with one language, and both are "homoiconic" in that their internal and external representations are essentially the same. They both have the ability to dynamically create new functions which may then be elaborated at the users's pleasure. Their only great drawback is that programs written in them look like King Burniburiach's letter to the Sumerians done in Babylonian cuniform! [...][edit] Use and advantages

One advantage of homoiconicity is that extending the language with new concepts typically becomes simpler, as data representing code can be passed between the meta and base layer of the program. The abstract syntax tree of a function may be composed and manipulated as a data structure in the meta layer, and then evaluated.

A typical demonstration of homoiconicity is the meta-circular evaluator.

[edit] Examples

Languages which are considered to be homoiconic include members of the Lisp family, Curl, REBOL, SNOBOL, XSLT, XQuery, TRAC, Io, Ioke, Joy, Factor, Pico, PostScript, Prolog, R, Tcl, Mathematica, and Julia.

In Von Neumann architecture systems (including the vast majority of general purpose computers today), raw machine code also has this property, the data type being bytes in memory.

[edit] Homoiconicity in LispHomoiconicity

Lisp uses S-expressions as an external representation for data and code. S-expressions can be read with the primitive Lisp function READ. READ returns Lisp data: lists, symbols, numbers, strings. The primitive Lisp function EVAL uses Lisp code represented as Lisp data, computes side-effects and returns a result. The result will be printed by the primitive function PRINT, which creates an external S-Expression from Lisp data.

Lisp data, a list using different data types: (sub)lists, symbols, strings and integer numbers.

((:name "john" :age 20) (:name "mary" :age 18) (:name "alice" :age 22))

Lisp code. The example uses lists, symbols and numbers.

(* (sin 1.1) (cos 2.03)) ; in Infix: sin(1.1)*cos(2.03)

Create above expression with the primitive Lisp function LIST and set the variable EXPRESSION to the result

(setf expression (list '* (list 'sin 1.1) (list 'cos 2.03)) )-> (* (SIN 1.1) (COS 2.03)) ; Lisp returns and prints the result(third expression) ; the third element of the expression-> (COS 2.03)

Change the COS term to SIN

(setf (first (third expression)) 'SIN);The expression is now (* (SIN 1.1) (SIN 2.03))

Evaluate the expression

(eval expression)-> 0.7988834

Print the expression to a string

(princ-to-string expression)-> "(* (SIN 1.1) (SIN 2.03))"

Read the expression from a string

(read-from-string "(* (SIN 1.1) (SIN 2.03))")-> (* (SIN 1.1) (SIN 2.03)) ; returns a list of lists, numbers and symbols[edit] Homoiconicity in Prolog1 ?- X is 2*5.X = 10.2 ?- L = (X is 2*5), write_canonical(L).is(_, *(2, 5))L = (X is 2*5).3 ?- L = (ten(X):-(X is 2*5)), write_canonical(L).:-(ten(A), is(A, *(2, 5)))L = (ten(X):-X is 2*5).4 ?- L = (ten(X):-(X is 2*5)), assert(L).L = (ten(X):-X is 2*5).5 ?- ten(X).X = 10.6 ?-

On line 4 we create a new clause. The operator ":-" separates the head and the body of a clause. With assert/1* we add it to the existing clauses(add it to the "database"), so we can call it later. In other languages we would call it "creating a function during runtime". We can also remove clauses from the database with abolish/1, or retract/1.

* The number after the clause's name is the number of arguments it can take (it's also called arity)

We can also query the database to get the body of a clause:

7 ?- clause(ten(X),Y).Y = (X is 2*5).8 ?- clause(ten(X),Y), Y = (X is Z).Y = (X is 2*5),Z = 2*5.9 ?- clause(ten(X),Y), call(Y).X = 10,Y = (10 is 2*5).

"call" is analogous to Lisp's "eval" function.

[edit] See alsoConcatenative programming languageCognitive dimensions of notations, design principles for programming languages' syntax.[edit] References Douglas McIlroy (1960) Macro Instruction Extensions of Compiler Languages Calvin Mooers and L. Peter Deutsch (1965) TRAC, A Text-Handling Language Alan Kay (1969) The Reactive Engine, PhD thesis (Accessed 20061229)[edit] External linksDefinition of Homoiconic at the C2 Wiki.Retrieved from "http://en.wikipedia.org/w/index.php?title=Homoiconicity&oldid=499134234"

One of the main design goals was that the input script of TRAC (what is typed in by the user) should be identical to the text which guides the internal action of the TRAC processor. In other words, TRAC procedures should be stored in memory as a string of characters exactly as the user typed them at the keyboard. If the TRAC procedures themselves evolve new procedures, these new procedures should also be stated in the same script. The TRAC processor in its action interprets this script as its program. In other words, the TRAC translator program (the processor) effectively converts the computer into a new computer with a new program language -- the TRAC language. At any time, it should be possible to display program or procedural information in the same form as the TRAC processor will act upon it during its execution. It is desirable that the internal character code representation be identical to, or very similar to, the external code representation. In the present TRAC implementation, the internal character representation is based upon ASCII. Because TRAC procedures and text have the same representation inside and outside the processor, the term homoiconic is applicable, from homo meaning the same, and icon meaning representation.

[...]

Following suggestion of McCullough, W. S., based upon terminology due to Peirce, C. S. s McIlroy. M. D., "Macro Instruction Extensions of Compiler Languages," Comm. ACM, p. 214-220; April, 1960.

A notable group of exceptions to all the previous systems are Interactive LISP [...] and TRAC. Both are functionally oriented (one list, the other string), both talk to the user with one language, and both are "homoiconic" in that their internal and external representations are essentially the same. They both have the ability to dynamically create new functions which may then be elaborated at the users's pleasure. Their only great drawback is that programs written in them look like King Burniburiach's letter to the Sumerians done in Babylonian cuniform! [...]
本文链接地址:https://www.jiuchutong.com/zhishi/303773.html 转载请保留说明!

上一篇:Mysql数学函数不求人数据库专栏,MySQL(mysql函数nvl)

下一篇:Python与Shell脚本的交互(shell和pycharm)

  • 华为电脑打不开了怎么办(华为电脑打不开文件怎么办)

    华为电脑打不开了怎么办(华为电脑打不开文件怎么办)

  • ns精灵球充电不亮灯(ns精灵球电量)

    ns精灵球充电不亮灯(ns精灵球电量)

  • 爱奇艺怎么取消续费(爱奇艺怎么取消自动续费微信)

    爱奇艺怎么取消续费(爱奇艺怎么取消自动续费微信)

  • p2000相当于什么显卡(p2200 相当于)

    p2000相当于什么显卡(p2200 相当于)

  • 微信新加的表情含义是什么(微信新加的表情包)

    微信新加的表情含义是什么(微信新加的表情包)

  • 电脑被偷了能定位吗(电脑偷了,具体能定位吗)

    电脑被偷了能定位吗(电脑偷了,具体能定位吗)

  • 苹果平板air和ipad区别(苹果平板Air和pro哪个好)

    苹果平板air和ipad区别(苹果平板Air和pro哪个好)

  • 手机电池是锂电池吗(手机电池是锂电池好还是石墨烯电池好)

    手机电池是锂电池吗(手机电池是锂电池好还是石墨烯电池好)

  • 苹果11有多防水(苹果11防水可以到达什么程度)

    苹果11有多防水(苹果11防水可以到达什么程度)

  • 微信公众号的主体信息可以变更吗(微信公众号的主要类型有)

    微信公众号的主体信息可以变更吗(微信公众号的主要类型有)

  • 苹果11开发者有什么用(苹果开发者有多少人)

    苹果11开发者有什么用(苹果开发者有多少人)

  • 华为m6怎么外接u盘(华为m6怎么接u盘)

    华为m6怎么外接u盘(华为m6怎么接u盘)

  • 在qq上怎么知道别人给自己的备注(在qq上怎么知道对方的位置)

    在qq上怎么知道别人给自己的备注(在qq上怎么知道对方的位置)

  • 快手播放量怎么算一次(快手播放量怎么提高)

    快手播放量怎么算一次(快手播放量怎么提高)

  • vivo手机怎么往mp3传歌(vivo手机怎么往mp3里传小说)

    vivo手机怎么往mp3传歌(vivo手机怎么往mp3里传小说)

  • 快手已戳对方知道吗(快手已戳对方知道了吗)

    快手已戳对方知道吗(快手已戳对方知道了吗)

  • usim卡应用老是跳出来(usim卡应用老是跳出来oppo)

    usim卡应用老是跳出来(usim卡应用老是跳出来oppo)

  • 痞子是什么意思(文学痞子是什么意思)

    痞子是什么意思(文学痞子是什么意思)

  • vivo手机的iQOO Pro 屏幕有多大(Vivo手机的恢复出厂设置在哪里)

    vivo手机的iQOO Pro 屏幕有多大(Vivo手机的恢复出厂设置在哪里)

  • ppt删除快捷键(ppt返回键在哪)

    ppt删除快捷键(ppt返回键在哪)

  • 大理石峡谷中横跨科罗拉多河的纳瓦霍桥,美国亚利桑那州北部  (© trekandshoot/Alamy)(大理石横切面)

    大理石峡谷中横跨科罗拉多河的纳瓦霍桥,美国亚利桑那州北部 (© trekandshoot/Alamy)(大理石横切面)

  • 尿急、尿频、尿痛怎么办(图文)(尿急尿频尿不尽吃什么药效果好)

    尿急、尿频、尿痛怎么办(图文)(尿急尿频尿不尽吃什么药效果好)

  • 锯齿原野中的Baron湖,爱达荷州 (© Patrick Brandenburg/Tandem Stills + Motion)(原版锯齿)

    锯齿原野中的Baron湖,爱达荷州 (© Patrick Brandenburg/Tandem Stills + Motion)(原版锯齿)

  • next在python中返回迭代器(python的next())

    next在python中返回迭代器(python的next())

  • 对方公司为什么一定要专票
  • 支付增值税会计科目
  • 逾期未申报是什么意思
  • 小规模纳税人销售已使用固定资产
  • 期末有留底税额可需要进行账务处理
  • 收到的普通发票需要认证吗
  • 帮别人买交强险,受益人是我,有影响吗
  • 行政单位工资支出标准
  • 纳税筹划成本支出怎么算
  • 个税扣除是扣我们的钱吗
  • 其他货币资金是资产类科目吗
  • 企业所得税税前扣除异常是什么意思
  • 待摊费用的金额
  • 多层股权结构设计控制法
  • 上报汇总和抄报是一个意思吗
  • 三证合一地税号查询
  • 所得税计税方法
  • 公司注销后银行账户怎么注销
  • 向境外支付违约金要代扣税吗
  • 个人网银测试要点
  • 应征增值税不含税销售额和免税销售额
  • 差额纳税的会计处理
  • 在win11
  • 路由器突然不能上网了显示红灯
  • 开机进入睡眠模式按哪个键解除
  • 本月损益类怎么结转
  • 小规模纳税人销售自己使用过的固定资产税率
  • 抵扣了的进项税可以冲销么
  • 购买专利权的会议纪要
  • 借出材料表
  • php框架yii
  • 转让土地需要办什么手续
  • php 冒泡
  • 微信公众号模板软件
  • transformer的解码器
  • jmeter接口串联
  • 深圳杯2020c题
  • 如何在js中给字母排序
  • dos命令怎么转到d盘
  • 代发工资如何计算
  • vue数据加载完成显示页面过渡动画
  • 实发工资知道如何发放吗
  • vue开发小技巧
  • 应付职工薪酬包括哪些二级科目
  • 已付款收货未收到发票怎么做账
  • 收到发票现金支付
  • 基本户转到法人账户会计分录
  • 借款可以抵货款吗
  • 利润表反映了什么能力
  • 个税没有达到起征点能摇号吗
  • 房产出租税率是多少
  • 培训费 会议费
  • 专项资金支出时间规定
  • 捐赠的资产属于什么科目
  • 财务人员的职工福利费应计入?
  • 虚拟机安装win7一直卡在完成安装
  • scanexplicit.exe - scanexplicit是什么进程 作用是什么
  • win7升级win10系统版本软件还有吗
  • win10 window
  • linux系统叫啥
  • cocos2dx场景切换
  • cocos2dx在不同安卓机型下scrollview裁剪失败
  • undefined reference to pthread
  • perl获取文件名
  • 请问在javascript程序中
  • jquery替换div内容
  • 安卓动态图标怎么实现
  • android camera setParameters failed 类问题分析总结
  • 一些常用的网络命令
  • js验证正则表达式
  • gridlayout动态添加view
  • HttpClient通过Post上传文件
  • 对于初学者的鼓励
  • 关于python整数类型
  • 江苏电子税务局官网登录入口
  • 投资联营的房产税纳税人是谁
  • 上报汇总之后怎么申报
  • 出口退税网上申报流程
  • 如何做好税务党建工作
  • 江苏房产税如何计算公式
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设