tcl/Itcl error: wrong # args: should be "itcl::class name { definition }" - tcl

I am currently learning Itcl language (based on tcl language)
and I wrote the following script.
the script is implementing a driver that should get 4 parameters and store them inside the private variables of the instance of the class
#!/bin/tclsh
package require Itcl
itcl::class driver {
# private variables
private variable bundle_id ""
private variable scope ""
private variable isSimulationModel ""
private variable isX ""
private method set_data_field {data_field_flag data_value} {
switch -- $data_field_flag {
-bundle {
set bundle_id $data_value
catch {unset bundle_id}
return
}
-scope {
set scope $data_value
catch {unset scope}
return
}
-isSimulationModel {
set isSimulationModel $data_value
catch {unset isSimulationModel}
return
}
-isX{
set isX $data_value
catch {unset isX}
return
}
}
return
}
constructor {bundle hdl_path is_simulation_model is_x} {
set_data_field -bundle $bundle
set_data_field -scope $hdl_path
set_data_field -isSimulationModel $is_simulation_model
set_data_field -isX $is_x
}
destructor {}
} #* _DRIVER_ * #
driver d 1 2 3 4
when I am trying to run it I get the following error :
wrong # args: should be "itcl::class name { definition }"
while executing "itcl::class driver {
# private variables
private variable bundle_id ""
private variable scope ""
private variable isSimulationModel ""
private v..."
(file "./driver.itcl" line 5)
can anyone help me and tell me what I did wrong that I am getting this error?

Inline comments have to begin with a semi-colon:
} ;#* _DRIVER_ * #
^
As it is right now, it looks like you are doing itcl::class driver { ... } #* _DRIVER_ * # with #* _DRIVER_ * # being 4 extra arguments (#*, _DRIVER_, * and #).
Read more about Tcl commenting on the wiki.

Related

Antlr How to avoid reportAttemptingFullContext and reportAmbiguity

In my java program im parsing many lines of code and to avoid ambiguous lines i used:
ParseTreeWalker walker = new ParseTreeWalker ();
if (!(lexerErrorListener.hasError() || parserErrorListener.hasError ()))
walker.walk (listener, tree);
else
line error
with the listener:
#Override
public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact,
BitSet ambigAlts, ATNConfigSet configs) {
hasError = true;
}
#Override
public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex,
BitSet conflictingAlts, ATNConfigSet configs) {
hasError = true;
}
input like: |U1,0 = comment generate ambiguity and fullcontext error with my grammar.
is a wrong approach or is there a way to handle these errors?
My Lexer:
lexer grammar LexerGrammar;
SINGLE_COMMENT : '|' -> pushMode(COMMENT);
NUMBER : [0-9];
VIRGOLA : ',';
WS : [ \t] -> skip ;
EOL : [\r\n]+;
// ------------ Everything INSIDE a COMMENT ------------
mode COMMENT;
COMMENT_NUMBER : NUMBER -> type(NUMBER);
COMMENT_VIRGOLA : VIRGOLA -> type(VIRGOLA);
TYPE : 'I'| 'U'| 'Q';
EQUAL : '=';
COMMENT_TEXT: ('a'..'z' | 'A'..'Z')+;
WS_1 : [ \t] -> skip ;
COMMENT_EOL : EOL -> type(EOL),popMode;
my parser:
parser grammar Parser;
options {
tokenVocab = LexerGrammar;
}
prog : (line? EOL)+;
line : comment;
comment: SINGLE_COMMENT (defComm | genericComment);
defComm: TYPE arg EQUAL COMMENT_TEXT;
arg : (argument1) (VIRGOLA argument2)?;
argument1 : numbers ;
argument2 : numbers ;
numbers : NUMBER+ ;
genericComment: .*?;
reportAmbiguity and reportAttemptingFullContext are not an indication that there was a syntax error. You can listen in on these events to know if they happen, but ANTLR has a deterministic approach to resolving this ambiguity (it uses the first alternative).
If you do not treat those as errors, you will get a proper parse tree out of your parse.

Fatal error: Uncaught TypeError: Argument 1 passed to Mage_Core_Model_Design_Package::getPackageByUserAgent()

I was getting a 500 error once I moved my magento 1.9 install from an old server to a new server. The old server was running php5 and this one is on 7. I am now getting the following error and I know I have to change some of the code, but I am not sure what:
Fatal error: Uncaught TypeError: Argument 1 passed to Mage_Core_Model_Design_Package::getPackageByUserAgent() must be of the type array, object given, called in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php on line 576 and defined in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php:586 Stack trace: #0 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(576): Mage_Core_Model_Design_Package::getPackageByUserAgent(Object(Zend_Log), 'design/theme/te...') #1 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(262): Mage_Core_Model_Design_Package->_checkUserAgentAgainstRegexps('design/theme/te...') #2 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(287): Mage_Core_Model_Design_Package->getTheme('template') #3 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(420): Mage_Core_Model_Design_Package->updateParamDefaults(Array) #4 /home1/acapps/flagstuff.com/app/code/core in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php on line 586
This is the code that starts on line 586 of Package.php
public static function getPackageByUserAgent(array $rules, $regexpsConfigPath = 'path_mock')
{
foreach ($rules as $rule) {
if (!empty(self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']])) {
self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value'];
return $rule['value'];
}
$regexp = '/' . trim($rule['regexp'], '/') . '/';
if (#preg_match($regexp, $_SERVER['HTTP_USER_AGENT'])) {
self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']] = true;
self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value'];
return $rule['value'];
}
}
return false;
}
Turns out I needed to change this:
public static function getPackageByUserAgent(array $rules, $regexpsConfigPath = 'path_mock')
to this
public static function getPackageByUserAgent($rules, $regexpsConfigPath = 'path_mock')
after that, it worked like a charm

How to replace string for each item in a list in jsonnet?

How to replace a value in a list in jsonnet. The basic example like this does not seem to work:
local users = import "../data/users.json";
// replace dots in username
local users_new = [
u + { replaced_username: std.strReplace(u.username, ".", "_") }
for u in users
];
{
data: {
[user.replaced_username]: {
username: user.username,
} for user in users_new
}
}
The error message is like this:
RUNTIME ERROR: Field does not exist: strReplace
templates/users.jsonnet:5:32-45 object <anonymous>
templates/users.jsonnet:11:17-38 thunk <b>
std.jsonnet:148:27 thunk <vals>
std.jsonnet:611:21-24
std.jsonnet:611:12-25 thunk <a>
std.jsonnet:611:12-36 function <anonymous>
std.jsonnet:611:12-36 function <anonymous>
std.jsonnet:148:13-28 function <anonymous>
templates/users.jsonnet:11:10-38 object <anonymous>
During manifestation
As I understand from the error message I can't use calculated values in keys or do I miss something here?
UPD: Turned out that std.strReplace function is not present in jsonnet version 0.9.5. Problem solved by copying that function into a template.
In this particular case, because the string to replace has a single character, you could locally implement the function with:
local strReplace(str, a, b) = (
assert std.length(a) == 1;
std.join(b, std.split(str, a))
);
strReplace(strReplace("hello world", "o", "0"), "l", "1")
Above example gives below output:
$ jsonnet -version
Jsonnet commandline interpreter v0.9.5
$ jsonnet strReplace.jsonnet
"he110 w0r1d"

doctrine 2.2 double type to a power

Within Entity Repository:
$qb = $this->createQueryBuilder('c');
//....
$qb->addSelect('POWER('.$qb->expr()->abs(
$qb->expr()->diff('c.latitude', $filter['latitude'])
).',2) AS ddst';
//....
return $qb->getQuery(); //to Pagerfanta with DoctrineORMAdapter
Errors:
QueryException: [Syntax Error] line 0, col 11: Error: Expected known function, got 'POWER'
QueryException: SELECT c, (POWER(ABS(c.delivery_latitude - 47.227163),2) AS ddst
FROM MyEntity c ORDER BY ddst ASC, c.created_at DESC (this is dql error)
What's not right? Dql doesn't support POWER. I didn't found it in qb-expressions.
And... Maybe it will be helpfull for someone. Answer:
//app/config/config.yml
doctrine:
dbal:
#.....
orm:
auto_generate_proxy_classes: %kernel.debug%
# auto_mapping: true #comment this line if isset
entity_managers:
default:
auto_mapping: true #from orm to here or custom mapping
dql:
numeric_functions:
power: Acme\MyBundle\DQL\PowerFunction #or power_num: ... it's an identifier
src/Acme/MyBundle/DQL/PowerFunction.php:
<?php
namespace Acme\MyBundle\DQL;
use Doctrine\ORM\Query\Lexer;
class PowerFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
{
public $numberExpression = null;
public $powerExpression = 1;
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
//Check for correct
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->numberExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$this->powerExpression = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'POWER(' .
$this->numberExpression->dispatch($sqlWalker) . ', ' .
$this->powerExpression->dispatch($sqlWalker) . ')';
}
}
And using (in MyEntityRepository):
$qb = $this->createQueryBuilder('c');
//some code
$qb->addSelect('power('.$yourNumber.',2) AS powered_num');
//'power' must be in lowercase!!!; if idetifier in config for example, 'power_num', then write 'power_num($yournumber,2)'
//some code ...
return $qb->getQuery(); //or getResult()
done.
I fixed the same issue thanks to this Bundle:
https://github.com/orocrm/doctrine-extensions
Here is the way to process.
1) Install the library:
composer require oro/doctrine-extensions
2) Add the DQL function to your doctrine config:
doctrine:
orm:
dql:
numeric_functions:
pow: Oro\ORM\Query\AST\Functions\Numeric\Pow
That's all.
Now Doctrine know how to handle the SQL POW function.
DQL is not SQL. It does not support a lot of the more obscure SQL functions like POWER.
If you want, you can create a native SQL query. See this doc for more info:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html

java.lang.Object.equals and java.lang.Object.hashCode have trouble with jruby object after serialization

I have some trouble using jruby objects into java
java side
package com.pp;
public interface ZeroI {
boolean equals(Object o);
int hashCode();
int hash();
}
package com.pp;
public class Tester {
public Object[] compare(ZeroI one, ZeroI two) {
return new Object[] {one.hashCode(), two.hashCode(), one.equals(two), one == two};
}
}
jruby side
include Java
import com.pp.Tester
import com.pp.ZeroI
module MMM
module Zero
def hash= value
#hash = value
end
def hash
#hash
end
def hashCode
#hash
end
def equals other
false
end
def == other
true
end
end
class OneClass
include ZeroI
include Zero
end
class TwoClass
include ZeroI
include Zero
end
def self.create clazz
begin
dump = IO.readlines("C:/#{clazz.to_s.rpartition('::')[2]}.txt", '').to_s
instance = Marshal.load dump
rescue => err
puts err.message
instance = clazz.new
dump = Marshal.dump instance
File.open("C:/#{clazz.to_s.rpartition('::')[2]}.txt", 'w') { |f| f.write dump }
end
instance
end
tester = Tester.new
one = create OneClass
two = create TwoClass
puts one
puts two
one.hash = 22
two.hash = 22
puts one.hashCode
puts two.hashCode
puts one.equals two
puts one == two
tester.compare(one, two).each { |value| puts value }
end
First pass result:
No such file or directory - C:/OneClass.txt
No such file or directory - C:/TwoClass.txt
#<MMM::OneClass:0x1971eb3>
#<MMM::TwoClass:0x1408a75>
22
22
false
true
22
22
true
false
true # it's OK because JAVA.equals works with JRUBY.==
false # it's OK because org.pp.ZeroI can't declare == method and JAVA.== is used
Second pass result (with deserialized objects)
#<MMM::OneClass:0xd510e8>
#<MMM::TwoClass:0x490342>
22
22
false
true
13046738 # but what is it?
31877484 # but what is it?
false # but what is it?
false
Can anybody explain it?
I don't know all the details about why this happens like it happens but I have a solution/workaround for you. (I've seen similar behaviour when passing objects that are created on the ruby side to the Java side.)
As far as I can tell JRuby needs to have already "seen" an instance of the class it is trying to unmarshal before it can get the Java-inheritance side of things right. It's almost as if creating an object within JRuby has an undocumented side-effect that registers the required inheritance hierarchy. If that isn't well worded it's because I don't understand it myself!
So the workaround is to simply create an instance of OneClass and TwoClass before doing the unmarshal. If I change the self.create method to the following:
def self.create clazz
begin
clazz.new # <<< just create an instance and throw it away!
dump = IO.readlines("C:/#{clazz.to_s.rpartition('::')[2]}.txt", '').to_s
instance = Marshal.load dump
rescue => err
puts err.message
instance = clazz.new
dump = Marshal.dump instance
File.open("C:/#{clazz.to_s.rpartition('::')[2]}.txt", 'w') { |f| f.write dump }
end
instance
end
Then the output of the two passes are as follows:
First pass
No such file or directory - C:/OneClass.txt
No such file or directory - C:/TwoClass.txt
#<MMM::OneClass:0x4de6f0ef>
#<MMM::TwoClass:0x4526ba64>
22
22
false
true
22
22
true
false
Second pass
#<MMM::OneClass:0x4858cca9>
#<MMM::TwoClass:0x3de4905a>
22
22
false
true
22
22
true
false
According to this bug report this is scheduled to be fixed in JRuby 1.7. It's worth noting that while the comments in the report say that the workaround is to call a method, passing an object instance in, it seems to be that the prior creation of the object is enough.