Skip to content
rdbyk edited this page May 24, 2018 · 133 revisions

Hints for Efficient Balisc/Scilab 6.x Coding

  • Use type instead of typeof, whenever possible.
  • Use nargin, nargout instead of argn.
  • Use x==[] instead of isempty(x), whenever possible.
  • Use x<>[] instead of ~isempty(x), whenever possible.
  • Use issquare instead of size, whenever possible.
  • Use length(x) instead of size(x,'*'), whenever possible.
  • Use x(length(x)) or x(size(x,'*') instead of x($), whenever possible.
  • Use &&, || instead of &, |, whenever possible.
  • Use ~(A || B) instead of ~A && ~B (cf. De Morgan's Laws).
  • Use ~(A && B) instead of ~A || ~B (cf. De Morgan's Laws).
  • Use execstr instead of evstr, whenever possible.
  • Use tokens instead of strsplit, whenever possible.
  • Use matrix(A,length(A),1) instead of A(:), whenever possible.
  • Use A.B instead of A("B") or getfield("B",A), whenever possible.
  • Use ones(m,n).*.A instead of repmat(A,m,n), whenever possible.
  • Use size(x)==1 instead of isscalar(x), whenever possible.
  • Use A=[] instead of A(:)=[], whenever possible.
  • Use .* and ./ instead * of / for integer types, whenever possible.
  • Use a & b instead of bitand(a,b), whenever possible.
  • Use a | b instead of bitor(a,b), whenever possible.
  • Use (a | b) & ~(a & b) instead of bitxor(a,b), whenever possible.
  • Use // Blah Blah only sparingly (cf. #488).
  • Use eye() instead of eye(A) or eye(n,m), whenever possible.
  • Use {} instead of cell(), whenever possible.

"Fifty" Ways to Kill Your Scilab 6.x (and Sometimes even Balisc)

  1. %t./%f
  2. sleep 1
  3. eye()\1
  4. 1:null()
  5. cell(-1)
  6. 1.*.eye()
  7. 1./.eye()
  8. 1.\.eye()
  9. 1./int8(0)
  10. 1:insert()
  11. sparse(1,1)
  12. eye()/eye()
  13. eye()\eye()
  14. expm(eye())
  15. mprintf("%%")
  16. msprintf("%%")
  17. min(eye(),"r")
  18. max(eye(),"r")
  19. [null(),null()]
  20. ereduc(eye(),1)
  21. cumsum(eye(),"r")
  22. cumprod(eye(),"r")
  23. triu([%s+%i,1;1,1])
  24. covStart(["a";"b"])
  25. [insert(),insert()]
  26. strsubst("","","","r")
  27. s=speye(2,2);s(s==0)=1
  28. strsubst('aaa','aa','a')
  29. S=struct();S(2,2)=struct()
  30. surf(1:2e3,1:2e3,(1:2e3)'*(1:2e3))
  31. f=gcf();xdel();save(TMPDIR+"/f.sod","f")
  32. function f(),ver()(1,2),end;macr2tree(f)
  33. a={%s};p=TMPDIR+"/a.sod";save(p,"a");listvarinfile(p)

to be continued ...

Predefined (and Protected) Variables Unique to Balisc

  • %balisc

    • Useful to check whether it is Balisc, e.g. use exists("%balisc").
    • Returns a single integer (e.g. 0), which indicates the version of Balisc

Functions Unique to Balisc

  • isprotected, protect, unprotect

    • Provide an interface to the protection mechanism of arbitrary variables
    • They supersede predef and are easy to use (cf. #420)

Clone this wiki locally