Hi Nikolay, On Tue, Jan 9, 2018 at 12:58 PM, Nikolay Aleksandrovich Pavlov <zyx....@gmail.com> wrote: > 2018-01-09 18:59 GMT+03:00 Yegappan Lakshmanan <yegapp...@gmail.com>: >> Hi Nikolay, >> >> On Mon, Jan 8, 2018 at 11:41 PM, Nikolay Aleksandrovich Pavlov >> <zyx....@gmail.com> wrote: >>> 2018-01-08 9:23 GMT+03:00 Yegappan Lakshmanan <yegapp...@gmail.com>: >>>> Hi, >>>> >>>> Which value you can use as the default value for a job >>>> type variable? I see that there is a test_null_job() function >>>> that returns a null job value (but it is supposed to be used >>>> only for testing). But I don't see any other way to initialize >>>> a variable to a null job value. Am I missing something? >>> >>> There is no such a thing as “abstract default value” in VimL, no >>> matter the type; to define something like this language would need to >>> have either constructions in which case return values of those >>> constructors called without arguments may be named “default value for >>> the type” (e.g. `list()` in Python returning empty list without >>> arguments) or be typed without support for uninitialized variables >>> (probably, only in part of the language) in which case whatever they >>> are initialized to when not explicitly initialized define “default >>> value for the type” (e.g. in C99 with `*tv = (typval_T) { .v_type = >>> VAR_STRING }` everything, but `v_type` in `tv` becomes zero; another >>> example is LabVIEW with “use default if unwired” terminals defaulting >>> to false/empty array/etc). All other defaults come from code authors, >>> for what you need to describe a task. >>> >>> So describe a task. >>> >> >> I am creating a plugin that runs a command asynchronously. >> This plugin supports only one asynchronous command at a time. >> If the async command is already running, the plugin will stop the >> current job and start a new job. >> >> I am using a variable to keep track of the current job. During the >> plugin startup or when the job exits, I need to set this variable >> to an empty or a sane value. Before starting a new job, I need to >> compare this variable against some default value to check whether >> a job is already running or not. As a workaround I am currently using >> another variable to keep track of whether the job is running or not. >> >> We can use the following default values for other variable types: >> Sting: "", Number: 0, List: [], Dict: {}. I am looking for some thing >> similar for the Job variable. > > They are by no means default values, these are *empty* values, nothing > more (see `:h empty()`, this applies to number too) >
How do we assign an empty value to a variable of Job type? > > And VimL is not typed, you *don’t* need what you are asking for: > just initialize variable to zero and check with `if var is 0`, this will yield > false if `var` happens to have type other then Number or value other > then zero. > Yes. I can use "is" to check whether var is set to 0. But this looks like a workaround. I was looking for a way to initialize the variable to an empty Job value. I will go with the "is" check for now. Thanks, Yegappan -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.