Skip to content
rdbyk edited this page Oct 17, 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) or size(x,'*')==1, 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.
  • Use a+imult(b) instead of complex(a,b), whenever possible.
  • Use [f,e]=frexp(x) instead of [f,e]=log2(x), whenever possible.
  • Use x instead of x<>0, whenever possible.
  • Use x.^(1./n) instead of nthroot(x,n), whenever possible.
  • Use a+b*%i instead of complex(a,b) or a+imult(b), whenever possible.
  • Use A(:,size(A,2):-1:1) instead of flipdim(A,2), 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:2):3
  5. 1:2:3:4
  6. min(1,)
  7. a().b=1
  8. 1:null()
  9. cell(-1)
  10. sin{1}=1
  11. 1.*.eye()
  12. 1./.eye()
  13. 1.\.eye()
  14. 1./int8(0)
  15. 1:insert()
  16. x=[];x()=1
  17. x=1;x()=[]
  18. printf("") or mprintf("") or msprintf("")
  19. sparse(1,1)
  20. eye()/eye()
  21. eye()\eye()
  22. expm(eye())
  23. p=%s;p{1}=1
  24. s="";s{1}=1
  25. {list()(:)}
  26. speye(-1,-1)
  27. if who(),end
  28. x(0:1)=1;x=2
  29. mprintf("%%")
  30. msprintf("%%")
  31. min(eye(),"r")
  32. max(eye(),"r")
  33. spzeros(-2,-1)
  34. [null(),null()]
  35. ereduc(eye(),1)
  36. sprand(-1,1,.1)
  37. while who(),end
  38. for w=who(),end
  39. sparse([0 0],1)
  40. read(%io(1),1,1) + [RETURN]
  41. cumsum(eye(),"r")
  42. sprand(1e3,1e3,1)
  43. cumprod(eye(),"r")
  44. fromJSON("{""""}")
  45. a=struct();a.b=a.b
  46. triu([%s+%i,1;1,1])
  47. covStart(["a";"b"])
  48. [insert(),insert()]
  49. write(6,1:3,"(I2)")
  50. strsubst("","","","r")
  51. s=speye(2,2);s(s==0)=1
  52. strsubst('aaa','aa','a')
  53. S=struct();S(2,2)=struct()
  54. L=list();L(2)=insert();L(1)
  55. u=["a","b"];v(1,:)=u,u(:,:)
  56. surf(1:2e3,1:2e3,(1:2e3)'*(1:2e3))
  57. x=tlist("x");function %x_s(a),end;-x
  58. f=gcf();xdel();save(TMPDIR+"/f.sod","f")
  59. function f(),ver()(1,2),end;macr2tree(f)
  60. 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)

Functions and Keywords Removed in Balisc

  • banner useless, nobody needs it
  • funptr outdated and useless
  • otherwise undocumented and redundant, use otherwise
  • resume redundant, use return
  • switch undocumented and redundant, use select

Clone this wiki locally