This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

premature end of expression?

Old posts that have not been replied to for several years.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

premature end of expression?

Post by caesar »

I'm keep getting this error: "Tcl error [next:list]: syntax error in expression "1042538818-": premature end of expression". Can someone point me the mistake so to fix the problem?

# list
proc next:list {nick uhost handle chan arg} {
global next
if {![next:moretools:chanflag $chan next]} {return 0}

set temp(list) [next:cmds get_list $chan]

set temp(post) ""
foreach temp(entry) $temp(list) {
set temp(duration) [duration [expr [clock seconds]-[lindex $temp(entry) 1]]]
lappend temp(post) "[lindex $temp(entry) 0] ($temp(duration))"
}

set temp(post) [expr {($temp(post) == "")?
"Currently empty.":
[join $temp(post) ", "]}]

putserv "NOTICE $nick :\002List\002: $temp(post)"

return 1
}

and a part from the next:cmds proc

# next:cmds
proc next:cmds {command {arg ""}} {
global next
switch -- $command {

"get_list" {
set channel [string tolower $arg]
return [expr {![info exists next(:list:$channel)]?
"":
$next(:list:$channel)}]
}

}
}

Thanks.
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

From what I can see, the only line doing any sort of Math, is

Code: Select all

set temp(duration) [duration [expr [clock seconds]-[lindex $temp(entry) 1]]]
You could try inserting spaces in the expr command, to seperate the -.

Otherwise, the code just looks like a structured minefield :P
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: premature end of expression?

Post by egghead »

caesar wrote:I'm keep getting this error: "Tcl error [next:list]: syntax error in expression "1042538818-": premature end of expression". Can someone point me the mistake so to fix the problem?

[snip]
set temp(duration) [duration [expr [clock seconds]-[lindex $temp(entry) 1]]]
Guess: the [lindex $temp(entry) 1] doesn't produce anything.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

foreach temp(entry) $temp(list) { 
set temp(duration) [duration [expr [clock seconds]-[lindex $temp(entry) 1]]] 
lappend temp(post) "[lindex $temp(entry) 0] ($temp(duration))" 
}
when pulling out one item from a list, the item is beeing handeled as a string, you have to split the string ($temp(entry)) before you can do lindex on it
Elen sila lúmenn' omentielvo
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Papillon wrote:

Code: Select all

foreach temp(entry) $temp(list) { 
set temp(duration) [duration [expr [clock seconds]-[lindex $temp(entry) 1]]] 
lappend temp(post) "[lindex $temp(entry) 0] ($temp(duration))" 
}
you are doing a loop on a list "$temp(list)", when pulling out one item from it, the item is beeing handeled as a string, you have to split the $temp(entry) before pulling out a element
Not true.

A list is simply a string, formatted in a way, that it can be interpreted differently.

To any normal and every day eye, a list may not allways look out of place.

Code: Select all

a b c d e f g
The above is a valid Tcl list, and can be obtained using

Code: Select all

set list [list a b c d e f g]
In reality, this is a list in it's most basic form, and looks like a string. It can be done as easy as setting it

Code: Select all

set list "a b c d e f g"
This is still a vlid list.

They start getting more advanced, when multiword elements, or special characters are placed in the list.

EG

Code: Select all

set list [list a b c "d{" e f g]
EQUALS
a b c {d{} e f g
On top of this, it is also possible to add lists into lists.

Code: Select all

set list [list a b c [list d e [list f g h] i] j]
EQUALS
a b c {d e {f g h} i} j
The list command returns a special formmated string, down to the simplest form. This string is called a list.

SO again, if the scripts at issue. A string is placed into the $temp(entry) variable, but it may be a ist formmated string.

Using my last example, follow the code flow in this example

Code: Select all

foreach entry $list {
  puts stdout "> $entry"
}
This would output

Code: Select all

> a
> b
> c
> d e {f g h} i
> j
Note the 4th line. It is a list.

This may be the exactly same princaple used in the script.

However, we can't see the point, where data is injected into the variables, thus can't locateand say either it is or isn't a vlid list.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

I appologise :oops: , I need to go back home and study the tclmanual again :-?
Elen sila lúmenn' omentielvo
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

No need.

With Tcl's lack of native arrays, you either have to trust hash tables (what Tcl calls arrays) or Tcl based list managment.

Both of these are trickier than using proper arrays, which can usualy be multi-dimerntional.

Tcl lists are one of the harder points of master. The fact they are stored as strings, means you have to continualy look at what commands you are using, and make sure you are using the right command at the right time.

One method is to make the variables

Code: Select all

set Suser [lindex $Lusers 0]
set Luser [list $Spermissions [string toupper $Suser]]
set Suser
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I've changed it to: set temp(duration) [expr [clock seconds] - [lindex [lindex $temp(list) 0] 1]]

and the same thing: Tcl error [next:list]: syntax error in expression "1042549664 - ": premature end of expression

have I missed something?
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Code: Select all

set temp(duration) [expr [clock seconds] - [lindex [lindex $temp(list) 0] 1]]
This serves no real purpose, unless the list is structured in such a way.

My guess is that you should be using the $temp(entry) variable in the last set of "lindex" commands.

However, this is impossible to tell.

First off, let run through the code.

$temp(list) is set, by running the command "next:cmds get_list $chan"

Looking at this procedure, it returns either NULL or the value of another variable.

We would need to see the procedure, that inserts data into this vartiable, to understand the structure of the list it creates.

Without this structure, we can't tell what the error is.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I've uploaded the tcl file on a friends ftp. Here is the link: http://www.geocities.com/walk3ry/next.txt
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

After having a look (though not a full route around), I am unable to find any real issues.

Q1: Does this error happen every time someone requests the list?
If yes, see Q2.
If no, see Q3.

Q2: Does it happen right after loading the bot, but nobody has join the channel?
If yes. I will have to look some more.
If no. see Q3.

Q3: Each time a person joins the channel, changes nickname part, or quits, do a list until it makes an error. Please post the message it gives, and the event that took place (nick, quit, join, part) just before the error.

Follow the above, and you should be able to get this a little further.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Actualy I don't get any error when a user joins the channel, normal or helper the helper get's his voice and the normal one get's his notices.
Once the game is over, the king and the pawn go back in the same box.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I havn't sugested that you get the error when they join.

The error occurs when a list is requested.

I need to know, where the data (or lack of) is coming from, that cuases it.

Information is changed, when a user joins, quits, parts or changes nicknames.

It is at these times the data becomes currept, but which one.

As such, you need to force it to send a list, each time of of these events occurs, and state after whcih one it occurs.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Oh and..

A1: yes and on other commands that use "duration".

A2: It seems to work fine, I'm getting the error only when I use one of the commands that use "duration". Normal users and helpers join the channel and the normal ones recive the notice (as shoud do) and the helpers recive an voice (again like should do).

Commands that use the "duration": .next and .list
Once the game is over, the king and the pawn go back in the same box.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

caesar wrote:Oh and..

A1: yes and on other commands that use "duration".

A2: It seems to work fine, I'm getting the error only when I use one of the commands that use "duration".
Caesar, there are 2 instances in your script where the "temp(duration)" is computed just after you have created the list by using "set temp(list) [next:cmds get_list $chan]".

By adding putlog statements can you inspect that this list is a proper list? Like as follows:

Code: Select all

set temp(list) [next:cmds get_list $chan]

foreach element $temp(list) {
   putlog "Element on list: $element"
}
Locked