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

  • void

Functions and Keywords Removed in Balisc

  • banner useless, nobody needs it
  • funptr outdated and useless
  • oldEmptyBehaviour was annoying, thus completely removed
  • otherwise undocumented and redundant, use else
  • read_csv redundant, use csvRead
  • resume redundant, use return
  • switch undocumented and redundant, use select
  • write_csv redundant, use csvWrite

Clone this wiki locally