assign

Update the whole structure

十年热恋 提交于 2019-12-24 10:48:13
问题 Suppose I have some function which returns a struct: (struct layer (points lines areas)) (define (build-new-layer height) ... (layer list-a list-b list-c)) I want to keep track of the last returned result something like: (define top-side (build-new-layer 0)) ; store the first result ... (set! top-side (build-new-layer 0.5)) ; throw away the first result and store the new one However, for that particular code I get the error: set!: assignment disallowed; cannot modify a constant constant: top

Why is this assignment ambiguous?

空扰寡人 提交于 2019-12-24 03:23:57
问题 Please note that this question is not about how to change the code below to make it work; rather, I am looking for some insight on why a compiler would find this assignment ambiguous: entity assignment_to_aggregates is end; architecture example of assignment_to_aggregates is type vowel_type is (a, e, i, o, u); type consonant_type is (b, c, d, f, g); type vowel_consonant_pair is record vowel: vowel_type; consonant: consonant_type; end record; signal my_vowel: vowel_type; signal my_consonant:

lambda to assign a value to global variable?

风格不统一 提交于 2019-12-24 01:56:14
问题 I'm using tkinter and trying to assign a value to a global variable on a button press. Here is the code: popup.add_command(label="Allow Moving Item", command=lambda: allowMoving=True) I'm getting the invalid syntax. Can you tell me how to work this around? Many thanks! 回答1: For entertainment purposes only. popup.add_command(label="Allow Moving Item", command=lambda: globals().update(allowMoving=True)) (Although globals() is not documented with the same "do not modify the return value" warning

Two-dimensional list wrongly assigning values in python

随声附和 提交于 2019-12-23 10:19:54
问题 class Board: def __init__(self): self.board = self.createBoard() def createBoard(self): line = [] for i in range(7): line.append(' ') board = [] for i in range(7): board.append(line) return board def showBoard(self): line = "| " for x in range(len(self.board)): for y in range(len(self.board)): line += self.board[x][y] + " | " print("-" * 29) print(line) line = "| " print("-" * 29) if __name__ == '__main__': board = Board() board.showBoard() board.board[1][1] = "O" board.showBoard() I was

Slice assignment to tensorflow variable

爱⌒轻易说出口 提交于 2019-12-22 18:26:17
问题 I am trying to assign values to slice of a variable in tensorflow, but the following error is shown: 'ValueError: Sliced assignment is only supported for variables'. Why is this error showing even though I am trying to do slice assignment to a variable. My code is something like this: var1 = var1[startx:endx,starty:endy].assign(tf.ones([endx-startx,endy-starty],dtype=tf.int32)) where var1 is a tensorflow variable. 回答1: The other answer is correct; doing any operation to a tf variable does not

Assign a define constant to const char * in C

白昼怎懂夜的黑 提交于 2019-12-22 18:23:42
问题 I'm not entirely sure which is the right way to assign a constant to a const char * . Are both ways okay? #define MSG1 "My Message #1" #define MSG2 "My Message #2" #define MSG3 "My Message #3" const char *opt1 = NULL; const char opt2[20]; switch(n){ case 1: opt1 = MSG1; // or should it be: strcpy(opt2, MSG1); break; case 2: opt1 = MSG2; // or should it be: strcpy(opt2, MSG2); break; case 3: opt1 = MSG3; // or should it be: strcpy(opt2, MSG3); break; } // ... printf("%s", optX); 回答1: opt1 =

Efficiency in assigning programmatically in R

戏子无情 提交于 2019-12-22 00:52:49
问题 In summary, I have a script for importing lots of data stored in several txt files. In a sigle file not all the rows are to be put in the same table (DF now switching to DT), so for each file I select all the rows belonging to the same DF, get DF and assign to it the rows. The first time I create a DF named ,say, table1 I do: name <- "table1" # in my code the value of name will depend on different factors # and **not** known in advance assign(name, someRows) Then, during the execution my code

Assign value to the same field of every element of non-scalar struct

风流意气都作罢 提交于 2019-12-21 04:27:35
问题 In Matlab, assigning cell arrays to a struct arrays field foo is possible with my_array(1000).foo = []; [my_array.foo] = some_cell{:}; Now what I would like to do is assign a single value to all fields in the array. But whatever I tried, Matlab would return error messages instead of silently assuming that if I want to assign a single element of size [1x1] , it should be assigned to all fields. I would be happy if I could simply say e.g.: my_array.foo = pi; ??? Incorrect number of right hand

Cannot Assign because it is a method group C#?

吃可爱长大的小学妹 提交于 2019-12-21 03:22:29
问题 Cannot Assign "AppendText" because it is a "method group". public partial class Form1 : Form { String text = ""; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { String inches = textBox1.Text; text = ConvertToFeet(inches) + ConvertToYards(inches); textBox2.AppendText = text; } private String ConvertToFeet(String inches) { int feet = Convert.ToInt32(inches) / 12; int leftoverInches = Convert.ToInt32(inches) % 12; return (feet + " feet and " +

Assign op in TensorFlow: what is the return value?

女生的网名这么多〃 提交于 2019-12-20 20:34:49
问题 I was trying to build an autoincrementing graph in TensorFlow. I thought that the assign op might be suitable for that, but found no documentation for it. I assumed that this op returns its value—like in C-like languages—and wrote the following code: import tensorflow as tf counter = tf.Variable(0, name="counter") one = tf.constant(1) ten = tf.constant(10) new_counter = tf.add(counter, one) assign = tf.assign(counter, new_counter) result = tf.add(assign, ten) init_op = tf.initialize_all