Add an arrow inside a list (mathematica) - list

I have a list of variables {a,b,c,d} (the lists I have are much bigger, this is a small example). I want to make the following list: {a->1, b->1, c->1, d->1}. I tried {a,b,c,d}->1, but this does not work and I dont know how to search for the right keywords.

That is pretty easy in Mathematica:
Thread[{a, b, c} -> 1]
Now, that you know this one function Thread, go into the documentation center and read through the material. Then you can look at the very bottom of the doc-page and you find plenty of guides and related functions that give you hints on where to go from there.

Related

Is there a way to get scrollstate from Lazyrow

I have made a LazyRow that i now want to be able to get the scrollposition from. What i understand Scrollablerow has been deprecated. (correct me if im wrong) The thing is that i cant make a scrollablerow so i thought lets make a lazy one then. but i have no clue how to get scrollposition from the lazyrow. i know how to get index but not position if that eaven exists. here is what i have tried.
val scrollState = rememberScrollState()
LazyRow(scrollState = scrollstate){
}
For LazyScrollers, there are separate LazyStates.
I think there's just one, in fact, i.e. rememberLazyListState()
Pass that as the scroll state to the row and then you can access all kinds of info. For example, you could get the index of the first visible item, as well as its offset. There are direct properties for this stuff in the object returned by the above initialisation. You can also perform some more complex operations using the lazyListState.layoutInfo property that you get.
Also, ScrollableRow may be deprecated as a #Composable, but it is just refactored, a bit. Now, you can use the horozontalScroll() and verticalScroll() Modifiers, both of which accept a scrollState parameter, which expects the same object as the one you've created in the question.
Usually, you'd use LazyScrollers since they're not tough to implement and also are super-performant, but the general idea is that they are used with large datasets whereas non-lazy scrollers are okay for small sized lists and stuff. This is because the lazy ones cache only a small fraction of the entire list, making your UI peformant, which is not something regular scrollers do, and not a problem for small datasets.
They're like equivalents of RecyclerView from the View System

Use the sheet number to check the active sheet

Before some code runs, I want to check it is the correct sheet.
I can use the sheet name, but my concern is that if someone changes the sheet name, the code won't run. The sheet index also seems to change if the sheet is moved.
Therefore I want to use something that doesn't change.
I believe the sheet number and sheet ID never change.
So I was hoping to use one of them, but I can't see a way of doing that.
What I want in non-coding language is:
If active sheet number = 4 then run the code or
If active sheet ID = 0123456789 then run the code.
Thanks to JPV's link, I have an answer and learned a few things.
You can't use the sheet number to check if the correct sheet is active.
You can use the getSheetId(), but the return you get is not useable.
To make it useable, you need to add getSheetId().toString().
To do the if statement, I needed two equal signs.
if (SpreadsheetApp.getActiveSheet().getSheetId().toString() == 0123456789) {do this when true}
I've been trying to solve this for days, so I should have come here and asked for help earlier.
The main thing I didn't know was the "toString()" part. It always seems so easy and obvious once I know.
Thank you, JPV.
Thanks to JPV's link, I have an answer and learned a few things.
You can't use the sheet number to check if the correct sheet is active.
You can use the getSheetId(), but the return you get is not useable.
To make it useable, you need to add getSheetId().toString().
To do the if statement, I needed two equal signs.
if (SpreadsheetApp.getActiveSheet().getSheetId().toString() == 0123456789) {do this when true}
I've been trying to solve this for days, so I should have come here and asked for help earlier.
The main thing I didn't know was the "toString()" part. It always seems so easy and obvious once I know.
Thank you, JPV.

autocompletion of parameter : list static fields without typing a ClassName::

How to make auto-completion list all (static) fields of a certain class that has appropriate variable-type when ctrl+space at a slot of parameter in a certain function?
Example
I tried to ctrl+space in the below code :-
(Code as text is here.)
Question: How to make it show E_1 E_2 E_3?
I don't mind another plugin if I really need one.
It currently works but only for enum :-
My workaround
In practice, to get smart clue, I have to type more (PrototypeList::) :-
Bounty Reason
Here is the result of the current answer (citizenmatt's):-
It is different, but still not show E_1 E_2 E_3.
Have you tried Smart Completion? This feature will only show completion items that are valid for the current context. I think it works in C++, too.
In fact, ReSharper does help you here. All of E_1, E_2 and E_3 are in the completion list, but not on the top of it - they are assigned lower scores because they need an additional qualifier. That said, looks like there is still an issue with scoring:
E_2 and E_3 are in the list too, but they are not shown alongside E_1. We'll investigate this (RSCPP-19501).

appending strings to lists in prolog

i'm a new on Prolog, and i'm already having some problems to understand, the thing
is, i was making a test on appending some strings introduced by console:
append_str([],Adder,Adder).
append_str([Head|Tail],Adder,Result):-
append_str(Tail,[Head|Adder],Result).
sread_str(String):-
read(String),
atom(String).
sinput:-
sinput_str([]).
sinput_str(Lista):-
sread_str(String),
sinput_str([String|List]).
sinput_str(List):-
append_str(List,[],Result),
nl,
display(Result),
nl.
And eventually always getting this output:
|-? sinput.
sinput.
hello.
hello.
world.
world.
9.
9.
'.'(hello,'.'(world,[]))
The number is just for the console to end asking for some more values, i don't know what is wrong, thank you guys in advance.
you should try to understand what happens when you enter a number, forcing sread_str to fail.
Prolog explores all the alternatives available to prove a given goal, and doing so change the variables, undoing such changes when a path fail. Such model it's complicated by side effects required by IO (the read/display builtins).
Then attempt first to have a working sinput_str, something like this
sinput_str([String|List]):-
sread_str(String),
sinput_str(List).
sinput_str([]).

How to create automatic a list of items used in a LaTeX-document?

I want to add items in a LaTeX-document. Say for example, that I want add hints to the document. I create a command, so I can call something similar to this:
\hint{foocareful}{Be careful with foo!}{foo is a very precious item and can easily be broken. Be careful, especially don't throw foo.}
This will be formatted in special way, to make it easy for the reader to recognize it as a hint. It gets a label, that can be referenced in the example with 'foocareful'.
In the appendix I want to add a list of all hints with references to them. Something like:
\begin{enumerate}
...
\item Be careful with foo! (\pageref{foocareful})
...
\end{enumerate}
But naturally I don't want to maintain this list by hand. How can I create automatically such a list?
One way to do it is to use the float package. I think that, at least, the floatrow package can also do what you want, and may also be more flexible. See you go, though.
Here's an example of something like you're trying to do using float:
\documentclass{article}
\usepackage{float}
\floatstyle{boxed}
\newfloat{hintbox}{H}{hnt}
\floatname{hintbox}{Hint}
\newcommand\hint[2]{%
\begin{hintbox}
#2
\caption{#1}
\end{hintbox}}
\begin{document}
\section{Hello}
\hint{Be careful with foo!\label{foocareful}}{%
foo is a very precious item and can easily be broken.
Be careful, especially don't throw foo.}
\hint{Don't worry about bar!\label{foocareful}}{%
Unlike foo, bar is pretty easily to get along with.}
\section{End}
\listof{hintbox}{List of Hints}
\end{document}
Have not done this in years, but I would look at the LaTeX source code for \tableofcontents and \listoffigures. I think the mechanism is generic and you can expand it to include your own lists.