[go: up one dir, main page]

Skip to content
rdbyk edited this page Dec 4, 2020 · 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.
  • Use A==B instead of isequal(A,B), whenever possible.
  • Use list(A(:),B(:)) instead of lstcat(A,B), whenever possible.
  • Use a:(b-a)/(n-1):b instead of linspace(a,b,n), whenever possible.
  • Use strrchr(file,'.') instead of fileparts(file,'extension')`, whenever possible.
  • Use strncpy(x,n) instead of part(x,1:n), whenever possible.
  • Use X=[] instead of X(:)=[] or X(:,:,...)=[], whenever possible.

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

  1. {1:$}
  2. ~who()
  3. sleep 1
  4. a().b=1
  5. 1|who()
  6. atan(1,)
  7. cell(-1)
  8. sin{1}=1
  9. 1.*.eye()
  10. 1./.eye()
  11. 1.\.eye()
  12. imult(%s)
  13. {1,2}'(1)
  14. 1./int8(0)
  15. int8(0).\1
  16. x=1;x()=[]
  17. p=1:$;p(:)
  18. a(list())=1
  19. eye()/eye()
  20. eye()\eye()
  21. expm(eye())
  22. {list()(:)}
  23. if who(),end
  24. A=1;A(1,%nan)
  25. for i=1:$,end
  26. min(eye(),"r")
  27. max(eye(),"r")
  28. struct("a",{})
  29. [null(),null()]
  30. ereduc(eye(),1)
  31. sprand(-1,1,.1)
  32. while who(),end
  33. for w=who(),end
  34. isvector(list())
  35. cumsum(eye(),"r")
  36. sprand(1e3,1e3,1)
  37. sparse([1 0.5],1)
  38. cumprod(eye(),"r")
  39. fromJSON("{""""}")
  40. triu([%s+%i,1;1,1])
  41. covStart(["a";"b"])
  42. [insert(),insert()]
  43. write(6,1:3,"(I2)")
  44. matrix(1,ones(34,1))
  45. s.a=1;getfield("b",s)
  46. saveafterncommands(1)
  47. strsubst("","","","r")
  48. permute([2,2],40:-1:1)
  49. strsubst('aaa','aa','a')
  50. S=struct();S(2,2)=struct()
  51. L=list();L(2)=insert();L(1)
  52. u=["a","b"];v(1,:)=u,u(:,:)
  53. gcf().color_map=rand(2e6,3)
  54. a=struct("b",null());a.b=a.b
  55. surf(1:2e3,1:2e3,(1:2e3)'*(1:2e3))
  56. x=tlist("x");function %x_s(a),end;-x
  57. f=gcf();xdel();save(TMPDIR+"/f.sod","f")
  58. deff('f(a,b)','plot2d(a,a,style=b)'),f(1,)
  59. A=ones(1000,1001);for i=1:1e4,try,inv(A),end,end
  60. 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
    • Shorthand for void()
    • Ignore outputs of functions, e.g. [–,b]=frexp(7.93) (cf. #1003)

Functions Unique to Balisc

  • bitpack, bitunpack

  • errmsgs

    • Returns predefined error messages and associated error numbers
  • fflush

    • Flushes streams opened by mopen or popen
  • flintmax

    • Return the largest integer that can be represented consecutively in a floating point value
  • funname

  • funref

  • inner

    • Move or create a variable to or in the inner (current) scope
  • intmax

    • Return the largest integer that can be represented in an integer type
  • intmin

    • Return the smallest integer that can be represented in an integer type
  • isprotected, protect, unprotect

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

  • outer

    • Move or create a variable to or in the outer (previous) scope
  • popen

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

  • swapbytes

  • typecast

  • void

Removed Functions and Keywords

Balisc 2

  • lstcat was buggy and slow, use list
  • bitstring is a very specialized function and is (now) redundant
    • e.g. use dec2base(typecast(%pi,'uint64'),2,64) instead of bitstring(%pi)
  • argn was redundant and rather slow, use nargin and nargout instead.

Balisc 1

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

Balisc 0

  • 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