[cap-talk] Abstractions that subsume capabilities
Pierre THIERRY
nowhere.man at levallois.eu.org
Fri Mar 14 00:20:22 EDT 2008
Scribit Richard Uhtenwoldt dies 11/03/2008 hora 21:04:
>
> def handle := <file:/etc/passwd>
> def contents := handle.getText()
> for line in contents.split("\n") {
> println(line)
> }
>
> [...]
>
> Since I found the E code in the E Idioms Quick Reference Card, I
> assume you all regard it as good, attack-resistant code. But
> obviously if it does not need surgery to make it more
> attack-resistant, the Haskell code does not either.
As Kevin said, this E code relies on the lexical scope to provide some
authority, so this code wouldn't work if it was loaded as an emaker. In
this case, you'd write it this way:
--8<---- filePrinter.emaker ---------------------------------------------
pragma.syntax("0.9")
def makeFilePrinter(file, output_function) {
def printer() {
def contents := file.getText()
for line in contents.split("\n") {
output_function(line)
}
}
return printer
}
--8<---------------------------------------------------------------------
Note that the authority to the device to print out to also needs to be
explicitely given.
You'd run that code this way:
? <import:filePrinter>(<file:foo.txt>, println)()
Quickly,
Pierre
--
nowhere.man at levallois.eu.org
OpenPGP 0xD9D50D8A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.eros-os.org/pipermail/cap-talk/attachments/20080314/b80f2adf/attachment-0001.bin
More information about the cap-talk
mailing list