scope

Nested Predicates In Prolog

送分小仙女□ 提交于 2020-06-16 17:24:34
问题 I am trying to write a predicate that ‘exists’ inside the ‘scope’ of another predicate . The reason I need this is because both predicates make use of the same very large parameters/arrays and the predicate I want to nest is doing self recurssion many times , so I want to avoid copying the same parameters . So , is there any way i can do this in Swi-Prolg ? Thanks in advance . 回答1: You don't need to. You have to realize that all the terms "named" by Prolog variable names are already global ,

Scope of imported modules/functions in Python

守給你的承諾、 提交于 2020-06-08 05:55:09
问题 I'm new here and am not 100% sure how to ask this question so I'll just dive right in. Should I be using import statements at the beginning of every function I write that import all of the various modules/functions I need for that function's scope? i.e. def func1() import os.path print func(2) do something with os.path def func2() import os.path do something with os.path Will this increase memory overheads, or other overheads, or is the import statement just mapping a local name to an already

accessing variable outside for loop

一笑奈何 提交于 2020-05-28 08:38:11
问题 how to access a string assigned some value in a for loop, outside the for loop i may provide you with the code for thy convenience for (Int32 i = 0; i < yourlist.Count; i++) { String str=(yourlist[i].ToString() + ","); } String str1 = (str).Substring(0, str.Length - 1); the error displayed is The name 'str' does not exist in the current context 回答1: The scope of the variable does not extend to outside the loop. If you want to access its value, you need to save it to another variable with a

accessing variable outside for loop

◇◆丶佛笑我妖孽 提交于 2020-05-28 08:36:57
问题 how to access a string assigned some value in a for loop, outside the for loop i may provide you with the code for thy convenience for (Int32 i = 0; i < yourlist.Count; i++) { String str=(yourlist[i].ToString() + ","); } String str1 = (str).Substring(0, str.Length - 1); the error displayed is The name 'str' does not exist in the current context 回答1: The scope of the variable does not extend to outside the loop. If you want to access its value, you need to save it to another variable with a

How to use variable from do block assignment line in a where clause?

孤人 提交于 2020-05-23 13:01:40
问题 I have the following sample of code: {-# LANGUAGE ScopedTypeVariables #-} main = do putStrLn "Please input a number a: " a :: Int <- readLn print a putStrLn "Please input a number b: " b :: Int <- readLn print b putStrLn ("a+b+b^2:" ++ (show $ a+b+c)) where c = b^2 For some reason I cannot use variable b in a where clause, the error I get is the following: Main3.hs:13:15: error: Variable not in scope: b | 13 | where c = b^2 | ^ Any ideas how to make b available in the where clause? 回答1: Use

Unable to access a method's local variables outside of the method in Java

不问归期 提交于 2020-05-22 08:00:53
问题 I am new to Java and am trying to access method variables outside of the method, but it doesn't work. Code is below: public class MethodAccess { public static void minus() { int a=10; int b=15; } public static void main(String[] args) { //Here i want to access variable names a & b that is in minus() int c = b - a; } } 回答1: Because a and b are local variables. If you want to access to them in your main method, you need to modify your code. For example : public class methodacess { private

Unable to access a method's local variables outside of the method in Java

懵懂的女人 提交于 2020-05-22 07:58:29
问题 I am new to Java and am trying to access method variables outside of the method, but it doesn't work. Code is below: public class MethodAccess { public static void minus() { int a=10; int b=15; } public static void main(String[] args) { //Here i want to access variable names a & b that is in minus() int c = b - a; } } 回答1: Because a and b are local variables. If you want to access to them in your main method, you need to modify your code. For example : public class methodacess { private

Unable to access a method's local variables outside of the method in Java

六眼飞鱼酱① 提交于 2020-05-22 07:57:05
问题 I am new to Java and am trying to access method variables outside of the method, but it doesn't work. Code is below: public class MethodAccess { public static void minus() { int a=10; int b=15; } public static void main(String[] args) { //Here i want to access variable names a & b that is in minus() int c = b - a; } } 回答1: Because a and b are local variables. If you want to access to them in your main method, you need to modify your code. For example : public class methodacess { private

Stylus: Creating mixins with loop results in “override” issue?

醉酒当歌 提交于 2020-05-17 06:07:22
问题 I have the following JSON-file: { "Primary": { "mixin": "primary", "color": "red" }, "Secondary": { "mixin": "secondary", "color": "blue" } } ...that I want to parse and dynamically create mixins off of it. Inspired by https://stackoverflow.com/a/35127312/2000741 I tried the following: colors = json('./colors.json', { hash: true }) for entry in colors mixin = scale[entry]["mixin"] value = scale[entry]["color"] // FIXME: Hack to cast mixin-name to string -> is there a better way? define("" +

Can I modify the target of a pointer passed as parameter?

血红的双手。 提交于 2020-05-16 13:55:12
问题 Can a function change the target of a pointer passed as parameter so that the effect remains outside the function? void load(type *parameter) { delete parameter; parameter = new type("second"); } type *pointer = new type("first"); load(pointer); In this minimal example, will pointer point to the second allocate object? If not, how can I get this kind of behavior? Update: To clarify my intention, here is the code I would use if the parameter would be a normal type instead of a pointer. In this