mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
E language with samples
This commit is contained in:
31
samples/E/Extends.E
Normal file
31
samples/E/Extends.E
Normal file
@@ -0,0 +1,31 @@
|
||||
# from
|
||||
# http://wiki.erights.org/wiki/Walnut/Ordinary_Programming/Objects_and_Functions
|
||||
def makeVehicle(self) {
|
||||
def vehicle {
|
||||
to milesTillEmpty() {
|
||||
return self.milesPerGallon() * self.getFuelRemaining()
|
||||
}
|
||||
}
|
||||
return vehicle
|
||||
}
|
||||
|
||||
def makeCar() {
|
||||
var fuelRemaining := 20
|
||||
def car extends makeVehicle(car) {
|
||||
to milesPerGallon() {return 19}
|
||||
to getFuelRemaining() {return fuelRemaining}
|
||||
}
|
||||
return car
|
||||
}
|
||||
|
||||
def makeJet() {
|
||||
var fuelRemaining := 2000
|
||||
def jet extends makeVehicle(jet) {
|
||||
to milesPerGallon() {return 2}
|
||||
to getFuelRemaining() {return fuelRemaining}
|
||||
}
|
||||
return jet
|
||||
}
|
||||
|
||||
def car := makeCar()
|
||||
println(`The car can go ${car.milesTillEmpty()} miles.`)
|
||||
21
samples/E/Functions.E
Normal file
21
samples/E/Functions.E
Normal file
@@ -0,0 +1,21 @@
|
||||
# from
|
||||
# http://wiki.erights.org/wiki/Walnut/Ordinary_Programming/Objects_and_Functions
|
||||
def makeCar(var name) {
|
||||
var x := 0
|
||||
var y := 0
|
||||
def car {
|
||||
to moveTo(newX,newY) {
|
||||
x := newX
|
||||
y := newY
|
||||
}
|
||||
to getX() {return x}
|
||||
to getY() {return y}
|
||||
to setName(newName) {name := newName}
|
||||
to getName() {return name}
|
||||
}
|
||||
return car
|
||||
}
|
||||
# Now use the makeCar function to make a car, which we will move and print
|
||||
def sportsCar := makeCar("Ferrari")
|
||||
sportsCar.moveTo(10,20)
|
||||
println(`The car ${sportsCar.getName()} is at X location ${sportsCar.getX()}`)
|
||||
69
samples/E/Guards.E
Normal file
69
samples/E/Guards.E
Normal file
@@ -0,0 +1,69 @@
|
||||
# from
|
||||
# http://wiki.erights.org/wiki/Walnut/Advanced_Topics/Build_your_Own_Guards
|
||||
def makeVOCPair(brandName :String) :near {
|
||||
|
||||
var myTempContents := def none {}
|
||||
|
||||
def brand {
|
||||
to __printOn(out :TextWriter) :void {
|
||||
out.print(brandName)
|
||||
}
|
||||
}
|
||||
|
||||
def ProveAuth {
|
||||
to __printOn(out :TextWriter) :void {
|
||||
out.print(`<$brandName prover>`)
|
||||
}
|
||||
to getBrand() :near { return brand }
|
||||
to coerce(specimen, optEjector) :near {
|
||||
def sealedBox {
|
||||
to getBrand() :near { return brand }
|
||||
to offerContent() :void {
|
||||
myTempContents := specimen
|
||||
}
|
||||
}
|
||||
return sealedBox
|
||||
}
|
||||
}
|
||||
def CheckAuth {
|
||||
to __printOn(out :TextWriter) :void {
|
||||
out.print(`<$brandName checker template>`)
|
||||
}
|
||||
to getBrand() :near { return brand }
|
||||
match [`get`, authList :any[]] {
|
||||
def checker {
|
||||
to __printOn(out :TextWriter) :void {
|
||||
out.print(`<$brandName checker>`)
|
||||
}
|
||||
to getBrand() :near { return brand }
|
||||
to coerce(specimenBox, optEjector) :any {
|
||||
myTempContents := null
|
||||
if (specimenBox.__respondsTo("offerContent", 0)) {
|
||||
# XXX Using __respondsTo/2 here is a kludge
|
||||
specimenBox.offerContent()
|
||||
} else {
|
||||
myTempContents := specimenBox
|
||||
}
|
||||
for auth in authList {
|
||||
if (auth == myTempContents) {
|
||||
return auth
|
||||
}
|
||||
}
|
||||
myTempContents := none
|
||||
throw.eject(optEjector,
|
||||
`Unmatched $brandName authorization`)
|
||||
}
|
||||
}
|
||||
}
|
||||
match [`__respondsTo`, [`get`, _]] {
|
||||
true
|
||||
}
|
||||
match [`__respondsTo`, [_, _]] {
|
||||
false
|
||||
}
|
||||
match [`__getAllegedType`, []] {
|
||||
null.__getAllegedType()
|
||||
}
|
||||
}
|
||||
return [ProveAuth, CheckAuth]
|
||||
}
|
||||
14
samples/E/IO.E
Normal file
14
samples/E/IO.E
Normal file
@@ -0,0 +1,14 @@
|
||||
# E sample from
|
||||
# http://wiki.erights.org/wiki/Walnut/Ordinary_Programming/InputOutput
|
||||
#File objects for hardwired files:
|
||||
def file1 := <file:myFile.txt>
|
||||
def file2 := <file:/home/marcs/myFile.txt>
|
||||
|
||||
#Using a variable for a file name:
|
||||
def filePath := "c:\\docs\\myFile.txt"
|
||||
def file3 := <file>[filePath]
|
||||
|
||||
#Using a single character to specify a Windows drive
|
||||
def file4 := <file:c:/docs/myFile.txt>
|
||||
def file5 := <c:/docs/myFile.txt>
|
||||
def file6 := <c:\docs\myFile.txt>
|
||||
9
samples/E/Promises.E
Normal file
9
samples/E/Promises.E
Normal file
@@ -0,0 +1,9 @@
|
||||
# E snippet from
|
||||
# http://wiki.erights.org/wiki/Walnut/Distributed_Computing/Promises
|
||||
when (tempVow) -> {
|
||||
#...use tempVow
|
||||
} catch prob {
|
||||
#.... report problem
|
||||
} finally {
|
||||
#....log event
|
||||
}
|
||||
18
samples/E/minChat.E
Normal file
18
samples/E/minChat.E
Normal file
@@ -0,0 +1,18 @@
|
||||
# from
|
||||
# http://wiki.erights.org/wiki/Walnut/Secure_Distributed_Computing/Auditing_minChat
|
||||
pragma.syntax("0.9")
|
||||
to send(message) {
|
||||
when (friend<-receive(message)) -> {
|
||||
chatUI.showMessage("self", message)
|
||||
} catch prob {chatUI.showMessage("system", "connection lost")}
|
||||
}
|
||||
to receive(message) {chatUI.showMessage("friend", message)}
|
||||
to receiveFriend(friendRcvr) {
|
||||
bind friend := friendRcvr
|
||||
chatUI.showMessage("system", "friend has arrived")
|
||||
}
|
||||
to save(file) {file.setText(makeURIFromObject(chatController))}
|
||||
to load(file) {
|
||||
bind friend := getObjectFromURI(file.getText())
|
||||
friend <- receiveFriend(chatController)
|
||||
}
|
||||
Reference in New Issue
Block a user