I'm currently trying to learn commodore 64 BASIC and I'm getting an error with my sleep function - text

I've been recently learning commodore 64 BASIC and I'm trying to create a text adventure game, and I'm getting an error concerning all of the sleep functions I used. My code is:
20 SLEEP(1000)
30 PRINT CLS
40 INPUT "START SURVEY?" ANSWER$
50 IF ANSWER$ == "YES"
60 PRINT CLS
70 PRINT "YOU BEGIN THE SURVER"
80 SLEEP(1000)
90 ELSE
100 SLEEP(1000)
110 PRINT CLS
120 PRINT "COME BACK ANOTHER TIME"
130 SLEEP(1000)
140 PRINT CLS
150 GOTO 10
the error is
ARRAY AT LINE 20
any ideas on how to fix this?

Related

Terminal limiting cpu usage while running lua

I was learning lua (specifically loops), and I need to run my code in the cmd to be able to use luaJit. Doing so, I notice that the loop were too slow. After that, I recreated the loop using js in the vscode and when I ran it, everything was normal. Then, I tried the same code, but compiled in the cmd, not surprising it was also slow. So, I think there is something limiting the cpu usage while running code in the terminal, but I have no idea. If someone knows how to fix it, I would be delighted.
All I did was open the terminal and run these commands:
luajit <path-to-the-code>
node <path-to-the-code>
Lua:
vscode: average 106 ms per test | 1.1 sec total
cmd: average 10 secs per test | 100 sec total
Js:
vscode: average 288 ms per test | 3 sec total
cmd: average 10 secs per test | 100 sec total
Lua code:
function test()
for x=1, 100000 do
print(x/100)
end
end
totalTime = 0
for x=1, 10 do
start = os.clock()
test()
totalTime = totalTime + os.clock() - start
end
print(totalTime/10)
Js code:
function test(){
for(let x = 1; x<100000; x++){
console.log(x/100)
}
}
let totalTime = 0
for(x = 1; x!=10; x++){
var start = Date.now()
test()
totalTime += Date.now()-start;
}
console.log(totalTime/10)

How many promises can Perl 6 keep?

That's a bit of a glib title, but in playing around with Promises I wanted to see how far I could stretch the idea. In this program, I make it so I can specify how many promises I want to make.
The default value in the thread scheduler is 16 threads (rakudo/ThreadPoolScheduler.pm)
If I specify more than that number, the program hangs but I don't get a warning (say, like "Too many threads").
If I set RAKUDO_MAX_THREADS, I can stop the program hanging but eventually there is too much thread competition to run.
I have two questions, really.
How would a program know how many more threads it can make? That's slightly more than the number of promises, for what that's worth.
How would I know how many threads I should allow, even if I can make more?
This is Rakudo 2017.01 on my puny Macbook Air with 4 cores:
my $threads = #*ARGS[0] // %*ENV<RAKUDO_MAX_THREADS> // 1;
put "There are $threads threads";
my $channel = Channel.new;
# start some promises
my #promises;
for 1 .. $threads {
#promises.push: start {
react {
whenever $channel -> $i {
say "Thread {$*THREAD.id} got $i";
}
}
}
}
put "Done making threads";
for ^100 { $channel.send( $_ ) }
put "Done sending";
$channel.close;
await |#promises;
put "Done!";
This isn't actually about Promise per se, but rather about the thread pool scheduler. A Promise itself is just a synchronization construct. The start construct actually does two things:
Ensures a fresh $_, $/, and $! inside of the block
Calls Promise.start with that block
And Promise.start also does two things:
Creates and returns a Promise
Schedules the code in the block to be run on the thread pool, and arranges that successful completion keeps the Promise and an exception breaks the Promise.
It's not only possible, but also relatively common, to have Promise objects that aren't backed by code on the thread pool. Promise.in, Promise.anyof and Promise.allof factories don't immediately schedule anything, and there are all kinds of uses of a Promise that involve doing Promise.new and then calling keep or break later on. So I can easily create and await on 1000 Promises:
my #p = Promise.new xx 1000;
start { sleep 1; .keep for #p };
await #p;
say 'done' # completes, no trouble
Similarly, a Promise is not the only thing that can schedule code on the ThreadPoolScheduler. The many things that return Supply (like intervals, file watching, asynchronous sockets, asynchronous processes) all schedule their callbacks there too. It's possible to throw code there fire-and-forget style by doing $*SCHEDULER.cue: { ... } (though often you care about the result, or any errors, so it's not especially common).
The current Perl 6 thread pool scheduler has a configurable but enforced upper limit, which defaults to 16 threads. If you create a situation where all 16 are occupied but unable to make progress, and the only thing that can make progress is stuck in the work queue, then deadlock will occur. This is nothing unique to Perl 6 thread pool; any bounded pool will be vulnerable to this (and any unbounded pool will be vulnerable to using up all resources and getting the process killed :-)).
As mentioned in another post, Perl 6.d will make await and react non-blocking constructs; this has always been the plan, but there was insufficient development resources to realize it in time for Perl 6.c. The use v6.d.PREVIEW pragma provides early access to this feature. (Also, fair warning, it's a work in progress.) The upshot of this is that an await or react on a thread owned by the thread pool will pause the execution of the scheduled code (for those curious, by taking a continuation) and and allow the thread to get on with further work. The resumption of the code will be scheduled when the awaited thing completes, or the react block gets done. Note that this means you can be on a different OS thread before and after the await or react in 6.d. (Most Perl 6 users will not need to care about this. It's mostly relevant for those writing bindings to C libraries, or doing over systems-y stuff. And a good C library binding will make it so users of the binding don't have to care.)
The upcoming 6.d change doesn't eliminate the possibility of exhausting the thread pool, but it will mean a bunch of ways that you can do in 6.c will no longer be of concern (of note, writing recursive conquer/divide things that await the results of the divided parts, or having thousands of active react blocks launched with start react { ... }).
Looking forward, the thread pool scheduler itself will also become smarter. What follows is speculation, though given I'll likely be the one implementing the changes it's probably the best speculation on offer. :-) The thread pool will start following the progress being made, and use it to dynamically tune the pool size. This will include noticing that no progress is being made and, combined with the observation that the work queues contain items, adding threads to try and resolve the deadlock - at the cost of memory overhead of added threads. Today the thread pool conservatively tends to spawn up to its maximum size anyway, even if this is not a particularly optimal choice; most likely some kind of hill-climbing algorithm will be used to try and settle on an optimal number instead. Once that happens, the default max_threads can be raised substantially, so that more programs will - at the cost of a bunch of memory overhead - be able to complete, but most will run with just a handful of threads.
Quick fix, add use v6.d.PREVIEW; on the first line.
This fixes a number of thread exhaustion issues.
I added a few other changes like $*SCHEDULER.max_threads, and adding the Promise “id” so that it is easy to see that the Thread id doesn't necessarily correlate with a given Promise.
#! /usr/bin/env perl6
use v6.d.PREVIEW; # <--
my $threads = #*ARGS[0] // $*SCHEDULER.max_threads;
put "There are $threads threads";
my $channel = Channel.new;
# start some promises
my #promises;
for 1 .. $threads {
#promises.push: start {
react {
whenever $channel -> $i {
say "Thread $*THREAD.id() ($_) got $i";
}
}
}
}
put "Done making threads";
for ^100 { $channel.send( $_ ) }
put "Done sending";
$channel.close;
await #promises;
put "Done!";
There are 16 threads
Done making threads
Thread 4 (14) got 0
Thread 4 (14) got 1
Thread 8 (8) got 3
Thread 10 (6) got 4
Thread 6 (1) got 5
Thread 16 (5) got 2
Thread 3 (16) got 7
Thread 7 (8) got 8
Thread 7 (9) got 9
Thread 5 (3) got 6
Thread 3 (6) got 10
Thread 11 (2) got 11
Thread 14 (5) got 12
Thread 4 (16) got 13
Thread 16 (15) got 14 # <<
Thread 13 (11) got 15
Thread 4 (15) got 16 # <<
Thread 4 (15) got 17 # <<
Thread 4 (15) got 18 # <<
Thread 11 (15) got 19 # <<
Thread 13 (15) got 20 # <<
Thread 3 (15) got 21 # <<
Thread 9 (13) got 22
Thread 18 (15) got 23 # <<
Thread 18 (15) got 24 # <<
Thread 8 (13) got 25
Thread 7 (15) got 26 # <<
Thread 3 (15) got 27 # <<
Thread 7 (15) got 28 # <<
Thread 8 (15) got 29 # <<
Thread 13 (13) got 30
Thread 14 (13) got 31
Thread 8 (13) got 32
Thread 6 (13) got 33
Thread 9 (15) got 34 # <<
Thread 13 (15) got 35 # <<
Thread 9 (15) got 36 # <<
Thread 16 (15) got 37 # <<
Thread 3 (15) got 38 # <<
Thread 18 (13) got 39
Thread 3 (15) got 40 # <<
Thread 7 (14) got 41
Thread 12 (15) got 42 # <<
Thread 15 (15) got 43 # <<
Thread 4 (1) got 44
Thread 11 (1) got 45
Thread 7 (15) got 46 # <<
Thread 8 (15) got 47 # <<
Thread 7 (15) got 48 # <<
Thread 17 (15) got 49 # <<
Thread 10 (10) got 50
Thread 10 (15) got 51 # <<
Thread 11 (14) got 52
Thread 6 (8) got 53
Thread 5 (13) got 54
Thread 11 (15) got 55 # <<
Thread 11 (13) got 56
Thread 3 (13) got 57
Thread 7 (13) got 58
Thread 16 (16) got 59
Thread 5 (15) got 60 # <<
Thread 5 (15) got 61 # <<
Thread 6 (15) got 62 # <<
Thread 5 (15) got 63 # <<
Thread 5 (15) got 64 # <<
Thread 17 (11) got 65
Thread 15 (15) got 66 # <<
Thread 17 (15) got 67 # <<
Thread 11 (13) got 68
Thread 10 (15) got 69 # <<
Thread 3 (15) got 70 # <<
Thread 11 (15) got 71 # <<
Thread 6 (15) got 72 # <<
Thread 16 (13) got 73
Thread 6 (13) got 74
Thread 17 (15) got 75 # <<
Thread 4 (13) got 76
Thread 8 (13) got 77
Thread 12 (15) got 78 # <<
Thread 6 (11) got 79
Thread 3 (15) got 80 # <<
Thread 11 (13) got 81
Thread 7 (13) got 82
Thread 4 (15) got 83 # <<
Thread 7 (15) got 84 # <<
Thread 7 (15) got 85 # <<
Thread 10 (15) got 86 # <<
Thread 7 (15) got 87 # <<
Thread 12 (13) got 88
Thread 3 (13) got 89
Thread 18 (13) got 90
Thread 6 (13) got 91
Thread 18 (13) got 92
Thread 15 (15) got 93 # <<
Thread 16 (15) got 94 # <<
Thread 12 (15) got 95 # <<
Thread 17 (15) got 96 # <<
Thread 11 (13) got 97
Thread 15 (16) got 98
Thread 18 (7) got 99
Done sending
Done!

RPGLE Compile Error: "The Name Or Indicator Is Not Defined"

I am taking an introductory course to IBM iSeries and Rational Developer, and I'm having difficulty compiling one of my RPGLE programs for a lab... Unfortunately, the lab is just a walkthrough of code we are supposed to compile without much explanation, so I have absolutely no clue about what I'm doing....
When I compile my program MARKSRPG.RPGLE, most of my errors say "The Name Or Indicator Is Not Defined"... I don't know what this means, and I'm unable to move ahead to see if what I have coded works thus far.
(UPDATE: I've made corrections to the suggestions, and now I'm getting different errors. "The types of the left and right hand side do not match in the EVAL operation", and "Operands are not compatible with the type of operator.)
The program is broken up into two files: MARKSRPG.RPGLE and MARKSDSP.DSPF. Here is the code for both, but my errors only show up on MARKSRPG.RPGLE
MARKSDSP:
A R RECORD1
A 1 33'Marks Calculator'
A 2 2USER
A 1 2SYSNAME
A 1 72DATE
A 4 24'Test 1:'
A 5 24'Test 2:'
A 6 24'Test 3:'
A 7 24'Labs:'
A 8 24'Exam:'
A TEST1 3 0B 4 32RANGE(0 100)
A TEST2 3 0B 5 32RANGE(0 100)
A TEST3 3 0B 6 32RANGE(0 100)
A LABS 3 0B 7 32RANGE(0 30)
A EXAM 3 0B 8 32RANGE(0 100)
A FIELD T B 2 71
A R RECORD2 CA03(03 'Exit')
A OVERLAY
A 10 23'Tests:'
A 11 18'Final Mark:'
A 12 17'Final Grade:'
A TESTOVRLL 3 0O 10 30
A NUMGRADE 3 0O 11 30
A GRADE 2X O 12 30
A 13 17'F3 - Exit'
MARKSRPG:
FMARKSDSP CF E WORKSTN
DLETGRADE S 1A
DTESTOVRLL S 3A
/FREE
EXFMT RECORD1;
DOW NOT(*IN03);
EXSR GETGRADE;
WRITE RECORD1;
EXFMT RECORD2;
IF *IN03= *OFF;
EXSR CLEARMARKS;
EXFMT RECORD1;
ENDIF;
ENDDO;
*INLR = *ON;
RETURN;
BEGSR GETGRADE;
LETGRADE = 'F';
TESTOVRLL = (TEST1 + TEST2 + TEST3)/3;
NUMGRADE = (TESTOVRLL/100*.30) + LABS +(EXAM/100*.35);
ENDSR;
BEGSR CLEARMARKS;
TEST1 = 0;
TEST2 = 0;
TEST3 = 0;
LABS = 0;
EXAM = 0;
TESTOVRLL = 0;
ENDSR;
/END-FREE
If you know of any useful resources for learning RPGLE and CLLE I'd appreciated it, and
any additional insight and help would be great too!
Thanks.
In your RPGLE member you have the wrong name for your display file. You have MARKSRPG instead of MARKSDSP.
I don't see LETGRADE defined anywhere either, that should go in your D specs.
D LETGRADE s 1a
I also don't see the subroutine CLEARMARKS defined anywhere. Since I also don't see an /end-free anywhere I'm going to assume you didn't paste all of the code for your RPGLE member.
Make those two changes I mentioned and then come back with any questions.
Here's a link to IBM's information center for the IBM i: http://publib.boulder.ibm.com/infocenter/iseries/v6r1m0/index.jsp?topic=/rzasd/sc09250802.htm

UIImageView crash when trying to set the frame

First here's my crash log:
Thread 0 Crashed:
0 libSystem.B.dylib 0x35176264 __kill + 8
1 libSystem.B.dylib 0x35176254 kill + 4
2 libSystem.B.dylib 0x35176246 raise + 10
3 libSystem.B.dylib 0x3518ad02 abort + 50
4 libstdc++.6.dylib 0x31432a20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x31a97594 _objc_terminate + 104
6 libstdc++.6.dylib 0x31430df2 _cxxabiv1::_terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x31430e46 std::terminate() + 10
8 libstdc++.6.dylib 0x31430f16 __cxa_throw + 78
9 libobjc.A.dylib 0x31a964c4 objc_exception_throw + 64
10 CoreFoundation 0x361857c2 +[NSException raise:format:arguments:] + 62
11 CoreFoundation 0x361857fc +[NSException raise:format:] + 28
12 QuartzCore 0x3148b222 CALayerSetPosition(CALayer*, CA::Vec2 const&, bool) + 134
13 QuartzCore 0x3148b190 -[CALayer setPosition:] + 32
14 QuartzCore 0x3148b0dc -[CALayer setFrame:] + 384
15 UIKit 0x35d15aba -[UIView(Geometry) setFrame:] + 182
16 UIKit 0x35d15928 -[UIImageView setFrame:] + 96
I have copied a part from the crash log. After line 16 there are my classes, which I cannot present here. In MyClass and MyMethod I change the frame of an imageView. My problem is that I cannot reproduce this bug and I want to reproduce it. What causes this log? I tried to release the imageView before I call the setFrame:, but it doesn't produce this error.
Any ideas how to get it? Or why this error happens some times?
I recognize this problem from one of my own projects. Usually when setFrame: crashes it's because your trying to set a NaN (Not a number). I don't know if you've dealt with NaN before, but if you haven't drop a comment and I'll provide information on how to deal with it.
EDIT: Had some time and thought I might give you an example.
So here's a code example to explain why the bug is hard to reproduce and how to fix it. I don't know what your code looks like, but your problem sounds similar enough to make me believe that you've done the same mistake as I did.
Consider the following code:
- (void)layoutSubviews {
CGRect imageFrame;
switch (self.state) {
case 0:
imageFrame = CGRectMake(0, 0, 100, 100);
case 1:
imageFrame = CGRectMake(10, 10, 50, 50);
}
self.imageView.frame = imageFrame;
}
Consider that self.state is 2, then imageFrame will never be initialized and will contain whatever was on that memory location, possibly NaN. The reason why this is hard to reproduce is that the crash will only occur when there is NaN on that memory location.
In my example the error is very easy to spot and it's likely that it's not as easy to spot in your code. If you can't find it yourself, feel free to post your code and I'll take a look at it. If you have any questions, don't hesitate to leave a comment.

How to get status from POS Printer

I'm trying to find a way to get paper status from a POS printer; I think I would use GS a, GS r sequence but I cannot understand how to return info from the printer; I'm under Linux, where does the POS printer returns info about status?
I've finally solved my problem ... i use PHP on linux box, here is the code, hope to help anyone:
<?php
$device="/dev/usb/lp0";
$printer=fopen($device, 'w');
//La sequenza di ESCAPE DLE EOT n consente
//la trasmissione in realtime
//dello status
//n=1: printer status
//n=2: printer offline status
//n=3: error status
//n=4: paper roll sensor status
//Per n=4 i bits valorizzati sono:
//BIT Off/On Dec Desc
//0 Off 0 not used, fixed to Off
//1 On 2 not used, fixed to On
//2,3 Off 0 Paper adequate
//2,3 On 12 Paper near end detected
//4 On 16 Not used, fixed to On
//5,6 Off 0 Paper present
//5,6 Off 96 Paper roll end
//7 Off 0 Not used, fixed to Off
fwrite($printer,kbyte(16).kbyte(4).kbyte(4));
//fwrite($printer,kbyte(29).kbyte(73).kbyte(69));
fclose($printer);
$r_printer=fopen($device, 'r');
$ret=fgets($r_printer);
fclose($r_printer);
$bit_val=ord($ret[0]);
print "Retval=".$bit_val;
if(($bit_val & 12) || ($bit_val & 96))
print "******Out of paper******\n";
else
print "---Paper ok\n";
function kbyte($num) {
return pack('C', $num);
}
?>

Resources