[Scilab-users] How to convert the ~ input placeholder <= Re: convert matlab code to scilab

Samuel Gougeon sgougeon at free.fr
Tue Nov 26 13:36:01 CET 2019


Hello Chin Luh,

Thanks a lot for your input.

Both cases -- input and output will have to be converted --, since the 
converter is also made to convert (sets of) functions definitions, not 
only scripts.

About the input case: Steven's answer is still not really clear to me. 
Doing some tests on Octave, we must anyway provide some input at calling 
time when  ~ is used as default input in the definition. AFAIU, this ~ 
could just be to make sure that no variable name used inside the 
function matches the name of the input argument in the function 
definition, since "~" alone can't be actually used as variable's name. 
In this case, for Scilab, any input ~ could be replaced with an 
improbable variable name like "%unused" or "%kwzxq", and that should do it.

Please, correct me if someone understands something else.

Best regards
Samuel

Le 26/11/2019 à 03:33, Chin Luh Tan a écrit :
> Hi Samuel,
>
> I think your assumption likely correct on the input and the output using ~
>
> https://www.mathworks.com/matlabcentral/answers/288016-tilde-doesn-t-work-for-ignoring-my-inputs
>
> "
> Youcanuse tilde to ignore input arguments when youdefinethe function.
> Youcannotuse tilde to ignore input arguments when youcallthe function.
> Youcannotuse tilde to ignore output arguments when youdefinethe function.
> Youcanuse tilde to ignore output arguments when youcallthe function.
> If you want to be able to specify only the third argument, there must 
> be some way for your function to disambiguate the one-input call from 
> a call that specifies only the third input. Usually in MathWorks 
> function this is done by specifying [] for the arguments for which the 
> user doesn't want to specify. In that case the code would use the 
> default value if eithernarginis too small or ifnarginis large enough 
> and the specified input argumentisempty.
> "
> From what I could think off, mat2sci conversion to replace ~ at the 
> output arguments should always be safe. As for the input, since the 
> tilde could not be used as input when calling function, I think there 
> should not be any cases that need to be implemented in conversion?
> Thanks.
> Regards,
> CL
>
>
> ---- On Tue, 26 Nov 2019 04:20:52 +0800 *Samuel Gougeon 
> <sgougeon at free.fr>* wrote ----
>
>     Le 23/11/2019 à 15:35, Samuel Gougeon a écrit :
>
>         HelloPhilipp, and to all (former ;-) matlabers,
>
>         Le 16/10/2019 à 11:46, P M a écrit :
>
>             Dear experts,
>
>             trying to convert a matlab code to scilab I come across
>             following line:
>
>             [~,~,Minstances_hat]  =  unique(B(:));
>
>             How to replace the "~" symbol?
>
>             B is the blue channel of a RGB image...hence a m x n
>             matrix of integers (type(B) = 8 )
>
>
>         This issue is now reported as bug 16250
>         <http://bugzilla.scilab.org/show_bug.cgi?id=16254>.
>
>         Solving this issue would improve the converter.
>         I may contribute to solve it. However, I do not use to use
>         Matlab or Octave. So i don't know how the ~ placeholder set in
>         the list of /inputs/ is processed inside the called function.
>         This message is a call for information about this topic.
>
>         Ignoring an output is trivial. As suggested by Stéphane, the
>         ans variable is a good candidate as replacement for ~,
>         just as a fake recipient, as in "[~, ia] = unique(A)"   => 
>         "[ans, ia] = unique(A)"
>
>         The meaning of ignoring an input is a priori completely
>         different, at least from a Scilab point of view.
>
>         This leads to the fact that, on the "function ..." line, the
>         converter will have to distinguish the list of inputs from the
>         list of outputs, and then process the same ~ character in 2
>         different ways.
>         This processing would have to run also when the "function ..."
>         line is split on several rows with the "..." continuation marks.
>
>         First, i will need an actual example of function call with ~
>         in the input list, runnable in Octave.
>         Any compact suggestion is welcome.
>         At least 2 use cases are expected: one calling a function
>         written in Octave/Matlab language (improperly called "macros"
>         in Scilab), the other one calling a hard-coded function.
>
>         Let's consider the first case, with a "macro":
>
>           * What does  the ~ sent placeholder pass to the function?
>             How is it detected/detectable inside the macro ?
>           * How is it processed by the function? Is there a generic
>             default processing, as replacing it with the empty matrix
>             [], or whatever else?
>
>     Where is the crowd of matlabers?
>
>     The page describing this
>     feature:https://fr.mathworks.com/help/matlab/matlab_prog/ignore-function-inputs.html
>     But i do not clearly understand it.
>     Apparently, "canceling" an input is done (only?) at the function
>     definition, not when calling it, unlike for the outputs.
>     If so, then /ans/ could also be used as a replacement, meaning
>     that anyway this input won't be used inside the function.
>
>     A test of call with Octave yields an error:
>
>     >> function [r, s] = funtest(a,b,c)
>     end
>     >> funtest(1,~,3)
>     parse error:
>       invalid use of empty argument (~) in index expression
>     >>> funtest(1,~,3)
>                      ^
>     >>
>
>     Any further insight is welcome.
>     Samuel
>
>
>     _______________________________________________
>     users mailing list
>     users at lists.scilab.org
>     http://lists.scilab.org/mailman/listinfo/users
>
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20191126/c2b115c1/attachment.htm>


More information about the users mailing list