| |
| /pliant/language/basic/setfield.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
abstract | |
| 17 |
[This module introduces the ability to replace a field by a couple of reading/writing functions.] ; eol | |
| 18 |
[If the field is named 'f', the reading function is called] ; fixed [ '. f' ] ; [and the writing function is called] ; fixed [ '. f :='] ; eol | |
| 19 |
[Please remind that a function named] ; fixed [ '. f' ] ; [is the same as a method named] ; fixed [ 'f'] ; [.] | |
| 20 |
doc | |
| 21 |
[Let's take an example:] | |
| 22 |
listing | |
| 23 |
var Array:Int a | |
| 24 |
a size := 2 | |
| 25 |
[is compiled as:] | |
| 26 |
listing | |
| 27 |
var Array:Int a | |
| 28 |
a 'size :=' 2 | |
| 29 |
[which is the same as:] | |
| 30 |
listing | |
| 31 |
var Array:Int a | |
| 32 |
'. size :=' a 2 | |
| 33 |
| |
| 34 |
| |
| 35 |
scope "/pliant/language/" "/pliant/install/" | |
| 36 |
module "/pliant/install/ring2.pli" | |
| 37 |
| |
| 38 |
function try_field e extra | |
| 39 |
arg_rw Expression e ; arg Str extra | |
| 40 |
if e:size<>2 | |
| 41 |
return | |
| 42 |
var Link:Expression var :> e 0 | |
| 43 |
var Link:Expression value :> e 1 | |
| 44 |
if var:size>=1 and var:0:is_pure_ident and var:0:ident<>"()" | |
| 45 |
var Link:Expression ee :> expression duplicate var subexpressions (expression ident var:0:ident+extra) (var 1 var:size-1) value | |
| 46 |
if (e might_compile_as ee) | |
| 47 |
e:properties := ee:0:properties | |
| 48 |
var:0:properties := ee:0:properties | |
| 49 |
if var:ident="()" and var:size>=2 and var:1:is_pure_ident | |
| 50 |
ee :> expression duplicate var subexpressions var:0 (expression duplicate var:1 ident var:1:ident+extra) (var 2 var:size-2) value | |
| 51 |
if (e might_compile_as ee) | |
| 52 |
e:properties := ee:1:properties | |
| 53 |
var:1:properties := ee:1:properties | |
| 54 |
| |
| 55 |
| |
| 56 |
public | |
| 57 |
| |
| 58 |
meta ':=' e | |
| 59 |
strong_definition | |
| 60 |
try_field e " :=" | |
| 61 |
| |
| 62 |
meta ':>' e | |
| 63 |
strong_definition | |
| 64 |
try_field e " :>" | |
| |