Skip to content
rdbyk edited this page Apr 8, 2019 · 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. sleep 1
  2. a().b=1
  3. atan(1,)
  4. cell(-1)
  5. sin{1}=1
  6. 1.*.eye()
  7. 1./.eye()
  8. 1.\.eye()
  9. imult(%s)
  10. {1,2}'(1)
  11. 1./int8(0)
  12. int8(0).\1
  13. x=1;x()=[]
  14. a(list())=1
  15. eye()/eye()
  16. eye()\eye()
  17. expm(eye())
  18. {list()(:)}
  19. if who(),end
  20. min(eye(),"r")
  21. max(eye(),"r")
  22. struct("a",{})
  23. [null(),null()]
  24. ereduc(eye(),1)
  25. sprand(-1,1,.1)
  26. while who(),end
  27. for w=who(),end
  28. isvector(list())
  29. cumsum(eye(),"r")
  30. sprand(1e3,1e3,1)
  31. sparse([1 0.5],1)
  32. cumprod(eye(),"r")
  33. fromJSON("{""""}")
  34. triu([%s+%i,1;1,1])
  35. covStart(["a";"b"])
  36. [insert(),insert()]
  37. write(6,1:3,"(I2)")
  38. s.a=1;getfield("b",s)
  39. strsubst("","","","r")
  40. strsubst('aaa','aa','a')
  41. S=struct();S(2,2)=struct()
  42. L=list();L(2)=insert();L(1)
  43. u=["a","b"];v(1,:)=u,u(:,:)
  44. gcf().color_map=rand(2e6,3)
  45. surf(1:2e3,1:2e3,(1:2e3)'*(1:2e3))
  46. x=tlist("x");function %x_s(a),end;-x
  47. f=gcf();xdel();save(TMPDIR+"/f.sod","f")
  48. deff('f(a,b)','plot2d(a,a,style=b)'),f(1,)
  49. A=ones(1000,1001);for i=1:1e4,try,inv(A),end,end
  50. C{1}=null();save("/tmp/T","C");clear("C");load("/tmp/T")

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

  • fflush

    • Flushes streams opened by mopen or popen
  • isprotected, protect, unprotect

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

    • Executes a command and connects a pipe to the corresponding process
  • rmfield

  • void

Removed Functions and Keywords

Balisc 2

  • getscilabkeywords redundant, use isprotected, librarieslist, libraryinfo, ...
  • predef had limited functionality, use isprotected, protect, unprotect

Balisc 1

  • banner useless, nobody needs it
  • funptr outdated and useless
  • getURL redundant, use http_xxx functions
  • oldEmptyBehaviour was annoying, thus completely removed
  • otherwise undocumented and redundant, use else
  • predef had limited functionality, use isprotected, protect, unprotect
  • read_csv redundant, use csvRead
  • resume redundant, use return
  • splitURL, use msscanf function to do the job
  • switch undocumented and redundant, use select
  • write_csv redundant, use csvWrite

Clone this wiki locally