Lists - possible to modify elements?

Is it possible to modify elements of Sophia lists? I guess not?
I was trying to do something like this from a stateful function:
put(state{tasks[taskID].fl = Call.origin})

tasks is defined in record state as tasks : list(task)
and task is:
record task = {
client : address,
fl : address,
taskValue : int,
workTime : int,
applyTime : int,
solutionSubmittedTime : int,
disputeStartedTime : int,
//blockHash : hash,
voteCommits : map(address, hash),
votes : map(int, int),
voters : map(int, address),
votesTotal : int,
votesClient : int,
votesFl : int,
stage : int
}

I get a compiler error:
Error: Http request for https://compiler.aepps.com/compile failed with status code 403. Status: .
Error data: {“reason”:“Type errors\nCannot unify list(task)\n and map(int, CryptoTask.task)\nwhen checking the assignment of the field\n tasks : list(task) (at line 84, column 36)\nto the old value __x and the new value\n __x {[taskID] @ __x = __x {fl = Call.origin}} :\n map(int, CryptoTask.task)\n”}

Shoud I use a mapping instead of a list for tasks (int to task)? Any other suggestions?

Thanks,
Vedran

another related question is would it be possible to remove elements from the middle of the list? i guess the answer is no :smiley:

And another question:
require(state.tasks[taskID].stage == 0, “Task needs to be free for application”)
throws a compilation error:
Cannot unify list(task)\n and map(int, CryptoTask.task)\nwhen checking the record projection at line 83, column 22\n state.tasks : list(task)\nagainst the expected type\n map(int, CryptoTask.task)\n"}

function require is defined as:
private function require(expression : bool, error : string) =
if(!expression)
abort(error)

I think you are somehow confusing list with some sort of an array, which it is not in Sophia.

From the look of your code it seems you should be able to change list(task) into map(int, task) since you are addressing your tasks by their Id in most places.

1 Like

yep, that’s what i’ll do. it’d be nice to have a double linked list as a built in type though, as it is doable with map(int, something) but it needs manual management of prev next fields (say after an element is removed)