Syntax error when calling a function with parameters in slim template - html

I have a slim template where I call a function like so:
textarea.form-control value = #function(parameter)
However I get the following error:
syntax error, unexpected '(', expecting ')'
Its strange that it does not like the '(" character because that's how I would imagine we would call functions with arguments from a template. What am I doing wrong and how can I call a function with an argument from a slim template. Apologies if this is a basic question, I am very new to slim and ruby

You don’t need the #:
textarea.form-control value = function(parameter)
As long as function and parameter are defined then this should work.
You may be confusing Ruby attributes (which use #) with functions/methods (which don’t). If you want to pass an attribute as the parameter, then you need the # in front of its name:
textarea.form-control value = function(#attribute)

Related

MATLAB | Invalid syntax for calling function 'cond' on the path. Use a valid syntax or explicitly initialize 'cond' to make it a variable

I want to extract data from a table called cond. As you can see from line 75 in the screenshot shown below, data Diameter corresponding to Drake can be successfully extracted using cond('Drake',:).Diameter.
screenshot
However, when I was trying to write this into a function called findCF(), things went wrong at line 78 with an error message
Invalid syntax for calling function 'cond' on the path. Use a valid
syntax or explicitly initialize 'cond' to make it a variable.
Can anybody tell me how to modify my code?
cond() is the name of a built-in function. Matlab tolerates variables whose names collide with functions, but it can result in weird things like this. In the line that produces the error, Matlab thinks you are trying to call the function cond(), not access the variable cond.
Rename the variable to something else.

ES6 unexpected token

I'm trying to use es6 to keep this code a little cleaner however my code creates a fatal error unexpected token. What am I doing wrong here?
Example: Works - old javascript
('/admin/candidate_profile/edit/contact_details/' + this.props.candidateUserId)
Example: Doesn't work - es6
{`/admin/candidate_profile/edit/contact_details/${this.props.candidateUserId}`}
If you are trying to set a variable equal to the above statement then you don't need the curly braces. For example, the below snippet should work:
let foo = `/admin/candidate_profile/edit/contact_details/${this.props.candidateUserId}`;

Argument by value not being passed in Praat

I have made a procedure in Praat script which looks like this:
procedure segment_allowed: .segment$
appendInfoLine: "The argument I got was: ", .segment$
.yes = 0
for i from 1 to allowed_segments_size
if allowed_segments$[i] = .segment$
.yes = 1
endif
endfor
endproc
It's basically trying to find out if .segment$ exists in a global array allowed_segments$.
The function when called like this:
call segment_allowed segment_label$
always outputs:
The argument I got was segment_label$
Why is the function/procedure not picking up the actual value and treating the variable like a string?
You are mixing the old syntax (the "shorthand") and the new syntax, and that's confusing things.
When you write call segment_allowed segment_label$, you are using the "shorthand", and in that (deprecated) syntax style variables are not automatically interpolated. If you want to use that style, you should write
call segment_allowed 'segment_label$'
to force interpolation.
A much better way to do it is to use the new syntax (which you are using in your procedure definition), which does a much more sensible variable interpolation. Using this new syntax (available from about version 5.4), your procedure call should be
#segment_allowed: segment_label$
which should do what you want.
As an aside, translating your current procedure call into this new syntax, which is easier to understand, what you were calling was
#segment_allowed: "segment_label$"
Also note that from 1 in for loops is redundant, since that is the default. And if what you are interested is just knowing whether the segment is there or not, you could break from the loop when a match has been found, like this (I also changed your i for .i, to keep things tidy):
procedure segment_allowed: .segment$
appendInfoLine: "The argument I got was: ", .segment$
.yes = 0
for .i to allowed_segments_size
if allowed_segments$[.i] = .segment$
.yes = 1
.i += allowed_segments_size
endif
endfor
endproc

Call to undefined function yii\helpers\mb_strlen() even though mbstring is enabled

I have enabled mbstring in my php.ini.It even shows in phpinfo().But still I am getting this error in yii2.
PHP Fatal Error 'yii\base\ErrorException' with message 'Call to undefined function yii\helpers\mb_strlen()
As #TomaszKane said in comment, mb_strlen() is native PHP function, so you need to call it as mbstrlen() without specifying the namespace.
Official documentation:
mb_strlen()
Also take a look at yii\helpers\StringHelper, mb_strlen() is used in several places. For example, if you are looking for byte length, there is special method byteLength(), you can call it like that:
use yii\helpers\StringHelper;
...
StringHelper::byteLength($string);
It's basically syntactic sugar of mb_strlen().

Is there a way to avoid using 'call' in Coffeescript?

I'm writing a simple Twitter client to play with coffeescript. I have an object literal with some functions that call each other via callbacks.
somebject =
foo: 'bar'
authenticateAndGetTweets: ->
console.log "Authorizing using oauth"
oauth = ChromeExOAuth.initBackgroundPage(this.oauthdetails)
oauth.authorize( this.afterLogin.call this )
afterLogin: ->
this.getTweets(this.pollinterval)
This code works perfectly. Edit: actually this.afterlogin should be sent as a callback above, not ran immediately, as Trevor noted below.
If, within authenticateAndGetTweets, I removed the 'call' and just ran:
oauth.authorize( this.afterLogin )
and don't use 'call', I get the following error:
Uncaught TypeError: Object [object DOMWindow] has no method 'getTweets
Which makes sense, since 'this' in afterLogin is bound to the thing that initiated the callback rather than 'someobject' my object literal.
I was wondering if there's some magic in Coffeescript I could be doing instead of 'call'. Initially I thought using the '=>' but the code will give the same error as above if '=>' is used.
So is there a way I can avoid using call? Or does coffeescript not obviate the need for it? What made '=>' not work how I expected it to?
Thanks. I'm really enjoying coffeescript so far and want to make sure I'm doing things 'the right way'.
As matyr points out in his comments, the line
oauth.authorize( this.afterLogin.call this )
doesn't cause this.afterLogin to be called as a callback by oauth.authorize; instead, it's equivalent to
oauth.authorize this.afterLogin()
Assuming that you want this.afterLogin to used as a callback by oauth.authorize, megakorre's answer gives a correct CoffeeScript idiom. An alternative approach supported by many modern JS environments, as matyr points out, would be to write
oauth.authorize( this.afterLogin.bind this )
There's no CoffeeScript shorthand for this, partly because Function::bind isn't supported by all major browsers. You could also use the bind function from a library like Underscore.js:
oauth.authorize( _.bind this.afterLogin, this )
Finally, if you were to define someobject as a class instead, you could use => to define afterLogin such that it's always bound to the instance, e.g.
class SomeClass
foo: 'bar'
authenticateAndGetTweets: ->
console.log "Authorizing using oauth"
oauth = ChromeExOAuth.initBackgroundPage(this.oauthdetails)
oauth.authorize(this.afterLogin)
afterLogin: =>
this.getTweets(this.pollinterval)
someobject = new SomeClass
you can put a lambda in the function call like so
auth.authorize(=> #afterLogin())
You have to use either the call or apply methods because they set the scope of the function (the value of this). The error results because the default scope is the window object.