RosettaCodeData/Task/Truncate-a-file/Bracmat/truncate-a-file.bracmat

24 lines
572 B
Plaintext

( ( trunc
= name length elif file c
. !arg:(?name,?length)
& fil$(!name,rb)
& fil$(,DEC,1)
& :?elif
& whl
' ( !length+-1:?length:~<0
& fil$() !elif:?elif
)
& (fil$(,SET,-1)|)
& whl'(!elif:%?c ?elif&!c !file:?file)
& fil$(!name,wb)
& fil$(,DEC,1)
& whl'(!file:%?c ?file&fil$(,,1,!c))
& (fil$(,SET,-1)|)
& !length:<0
)
& put$("I have a secret to tell you. Listen:","test.txt",NEW)
& ( trunc$("test.txt",20)&out$(get$("test.txt",STR))
| out$"File too short"
)
);