所以,我想在Commodore 64 BASIC中编写更大的函数。到目前为止,从我从其他来源(例如各种C64 wiki,以及C64本身的用户手册)看到的,函数定义只能是一行。 也就是说,我似乎无法在BASIC中找到括号中的类似构造/其他语言用来描述代码块的其他内容。
有谁知道我如何在BASIC中编写多行代码块?
单行函数示例:
success: function (data) {
if (data.result == 0) {
$('.div-errors').replaceWith($(data["view"]));
$btn.prop("disabled", false);
}
else {
$("#myModal").modal('hide');
$btn.prop("disabled", false);
$('#row' + data.id).html(data.value);
}
}
但我做不了类似的事情:
10 def fn X(n) = n + 1
20 print fn X(5) rem Correctly called function. This will output 6
感谢您的时间!
答案 0 :(得分:7)
可悲的是,C64 BASIC不支持更复杂的功能。
但它支持更复杂的子程序,这就是你想要的。
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myDArr = JSON.parse(xmlhttp.responseText);
details = myDArr
//console.log(myDArr.marketdetails)
};
itemsProcessed++
}
xmlhttp.open("GET", url2, true);//<-- put this outside the onreadystatechange handler
xmlhttp.send();//<-- put this outside the onreadystatechange handler
不幸的是,在C64 BASIC中将参数传递给子程序并从中返回值不是形式化的结构,所以你只需要处理如上所示的普通变量。
答案 1 :(得分:1)
从我的记忆中,你可以使用colan虚拟地在一行上执行多个命令。不是最优雅的解决方案,但会让你解决问题:
10 def fn X(n) =
20 n = n + 1
30 print n
40 rem I'd like the definition of function X to end at line 30 above
50 fn X(5) rem Produces syntax error on line 40
变为
10 n=n+1: print n
请注意,您无法传递参数,因此您必须声明事物并让BASIC堆栈为您处理。通常我会像这样构建程序:
1 rem lines 1-99 are definitions.
2 n% = 0 : rem this declares the variable n as an integer, initializing it to 0
100 rem lines 100-59999 are the core code
101 n%=5 : gosub 60100
59999 end : rem explicit end of the program to ensure we don't run into our subroutine block
60000 rem lines 60000+ are my subroutines..
60100 n% = n% + 1 : print n% : return
已经有一段时间了;从内存中,%字符是将变量声明为整数,类似于$将其声明为字符串。
答案 2 :(得分:0)
您可以将现有变量和数学命令与DEF FN
一起使用,例如,如果您希望{4} nybbles中的PRINT
0到10,则可以执行此操作:
0 DEF FN B(X)=SGN(X AND B)
1 FOR I=0 TO 10: REM OUR COUNTER
2 B=8: REM OUR BIT MARKER (128, 64, 32, 16, 8, 4, 2, 1)
3 FOR J=0 TO 3: REM WE WANT 4-BIT NYBBLES, SO 0 TO 3 INCLUSIVE
4 PRINT RIGHT$(STR$(FN B(I)),1);: REM CALLS OUR FUNCTION
5 B=B/2: REM MOVES TO NEXT BIT MARKER
6 NEXT J: REM PROCESS FOR LOOP J
7 PRINT: NEXT I: REM NEW LINE THEN PROCESS FOR LOOP I
我尝试过嵌套功能,但它太混乱了。事实上,我没有看到很多使用DEF FN
的商家信息。也许一些高级工匠时髦BASIC程序员使用它们?