聚合全网技术文章,根据你的阅读喜好进行个性推荐
新的引擎版本号更新至0.4。运行可靠性得到大幅度提高。
在开发过程中,我们大量使用洛书本身去编写一些配套组件,并结合反馈,修正了ELS0.1.3内核的大量问题。包括:
等。。。
# 这是注释,英文关键词的代码 def func() print('hello,world!') ; func()
如果 1 > 2 则 打印('你好') 另外 2<3 则 打印('你好') 否则 打印('你好') ; if 1>2 so print('hello') elif 2<3 so print('hello') else print('hello') ; if 1>2 : print('hello') elif 2<3 : print('hello') else: print('hello') ; 当 1<2 时 ; with 1<2 do ; with 1<2 : ;
修复0.1版本标准库存在的bug,完善标准库的英文函数支持
增加了从C代码字符串运行洛书的能力,具备脚本打包能力,可以免去文件系统的依赖
举个例子
方法 a() 返回 b,b是一个方法,所以f1 = a(),f1的值为方法b(),可以写f1()来调用方法。
洛书的方法可以随时被覆盖或重写,并且在运行到调用/声明位置时才会生效
a = 1 print(a) def a() print('hello') ; a() # 运行结果 #>1 #>hello
原生支持类 、构造函数、继承、多态、封装等面向对象的编程方式,支持动态创建对象。并且利用成员函数绑定的方式,可以有效减少继承与重写的使用,简化代码逻辑,降低复杂度。
# 函数 Sayhello def Sayhello(this) print(this.name) ; # 创建类 Student,有一个属性 name,有一个方法sayhello Student ={} def Student::Student(name) var this = {} this.name = name this.sayhello = Sayhello rt this ; # 创建类 People,有一个方法 say,与Student中sayhello方法共用一个 Sayhello()函数,Sayhello可以同时绑定给两个类 People ={} def People::People(name) var this = { name = name, say = Sayhello} rt this ; # 子类 CollegeStudent 单继承自 Student,重写sayhello方法 CollegeStudent ={} def CollegeStudent::CollegeStudent(name) $ this = Student:(name) # 生成 this对象 this.school = 'College' # 添加 this对象的 school 属性 this.sayhello = CollegeStudent.sayhello rt this ; def CollegeStudent::sayhello() print('college:\nname:'& this.name &'\nschool:' &this.school) ; # p1对象 p1 = People:('Tom') p1::say() # s1对象 s1 = Student:('Kate') s1::sayhello() # cs1对象 cs1 = CollegeStudent:('Jane') cs1::sayhello() exit(0)
感谢 凹语言 大佬提供的 样例,洛书也对BF语言的虚拟机进行了实现,作为洛书图灵完备性的一个副证。
附上相关代码:
#!/bin/els 引('字符串') BF机 ={} 方法 BF机::BF机(代码) $ 此 = {} 此.输出内容 = "" 此.指令 = 代码 此.内存 = {} 此.指令地址 = 1 此.代码地址 = 0 $ 甲 = 0 当 甲<3000 : 甲++ 此.内存[甲]=0 ; 此.运行 = BF机.运行 回 此 ; 方法 BF机::运行() 当 此.代码地址 != 值(长度(此.指令)) : 此.代码地址 = 此.代码地址 + 1 令 甲 = 截取(此.指令,此.代码地址,1) 如果 甲==">" : 此.指令地址 = 此.指令地址 + 1 另外 甲=="<" : 此.指令地址 = 此.指令地址 - 1 另外 甲=="+" : 此.内存[此.指令地址] = 此.内存[此.指令地址] + 1 另外 甲=="-" : 此.内存[此.指令地址] = 此.内存[此.指令地址] - 1 另外 甲=="[" : 如果 此.内存[此.指令地址]==0 : BF机.循环指令(此,1) ; 另外 甲=="]" : 如果 此.内存[此.指令地址]!=0 : BF机.循环指令(此,-1) ; 另外 甲=="." : 此.输出内容 = 此.输出内容 & 字节(此.内存[此.指令地址]) ; ; ; 方法 BF机::循环指令(指令) $ 甲 = 指令 当 甲!=0 : 如果 截取(此.指令,此.代码地址+指令,1)=='[' : 甲++ ; 如果 截取(此.指令,此.代码地址+指令,1)==']' : 甲-- ; 此.代码地址 = 此.代码地址 + 指令 ; ; 机器1 = BF机:("++++++++++[>++++++++++<-]>++++.+.") 机器1::运行() 打印(机器1.输出内容) 退()
#!/bin/els import('string') Bfvm ={} #BF虚拟机类 def Bfvm::Bfvm(code) #构造函数,创建一个bf虚拟机 $ this = {} this.out = "" #输出内容 this.code = code #程序 this.men = {} #内存 this.pos = 1 #指令指针 this.pc = 0 #读取code的位置 $ i = 0 #初始化内存空间 with i<3000 : i++ this.men[i]=0 ; this.run = Bfvm.run #绑定成员函数 rt this ; def Bfvm::run() #运行bf虚拟机 var x with this.pc != val(length(this.code)) : this.pc = this.pc + 1 x = mid(this.code,this.pc,1) if x==">" : this.pos = this.pos + 1 elif x=="<" : this.pos = this.pos - 1 elif x=="+" : this.men[this.pos] = this.men[this.pos] + 1 elif x=="-" : this.men[this.pos] = this.men[this.pos] - 1 elif x=="[" : if this.men[this.pos]==0 : Bfvm.bfloop(this,1) ; elif x=="]" : if this.men[this.pos]!=0 : Bfvm.bfloop(this,-1) ; elif x=="." : this.out = this.out & char(this.men[this.pos]) elif x=="," : this.men[this.pos] = ascii(input()) ; ; ; def Bfvm::bfloop(inc) #私有方法,没有在构造函数中被绑定 $ i = inc with i!=0 : if(wmid(this.code,this.pc+inc,1)=='['): i= i+1 ; if(wmid(this.code,this.pc+inc,1)==']'): i= i-1 ; this.pc = this.pc + inc ; ; b1 = Bfvm:("++++++++++[>++++++++++<-]>++++.+.") b1::run() #b1::bfloop() #如果运行本行会引发报错,调用的表达式不是函数 print(b1.out) exit(0)
评论删除后,数据将无法恢复
洛书 1.5.3 发布 — 完成 1.5.1 周期内数十处反馈修订
1.5.1版本相关信息可以阅读此处
相比上一个版本,我们做了哪些更新?
新的内核版本
新的引擎版本号更新至0.4。运行可靠性得到大幅度提高。
修复大量BUG
在开发过程中,我们大量使用洛书本身去编写一些配套组件,并结合反馈,修正了ELS0.1.3内核的大量问题。包括:
等。。。
更多新功能
新增一套英文关键词,同时用户可以自由修改、添加、删除自定义的关键词。
新的语法,弱化 则/so 时/do 等二级关键词(暂时不删除,但已经不再推荐使用,后期版本会移除),统一为python风格的 :
新的标准库
修复0.1版本标准库存在的bug,完善标准库的英文函数支持
新的运行模式
增加了从C代码字符串运行洛书的能力,具备脚本打包能力,可以免去文件系统的依赖
新数据结构与面向对象
新数据结构设计总则
举个例子
方法 a() 返回 b,b是一个方法,所以f1 = a(),f1的值为方法b(),可以写f1()来调用方法。
洛书的方法可以随时被覆盖或重写,并且在运行到调用/声明位置时才会生效
类与面向对象
原生支持类 、构造函数、继承、多态、封装等面向对象的编程方式,支持动态创建对象。并且利用成员函数绑定的方式,可以有效减少继承与重写的使用,简化代码逻辑,降低复杂度。
图灵完备性测试
感谢 凹语言 大佬提供的 样例,洛书也对BF语言的虚拟机进行了实现,作为洛书图灵完备性的一个副证。
附上相关代码:
1.5.3预览周期意见征集正在进行之中,您可以向相关仓库提交issues来反馈BUG及相关意见,我们将认真倾听您的每一条意见,并根据发展规划对其进行处理。