Where are `_stdlib_getTypeName()` & `_stdlib_getDemangledTypeName()` declared? -- Swift - swift

I'm toying with some introspection in Swift and it seems like if you want to get the class of an object in a printable version, these are the best options. (introduced in beta 6.0).
_stdlib_getTypeName(someClass)
_stdlib_getDemangledTypeName(someClass) // A slightly cleaner version
I was hoping to find other introspection methods, but unfortunately, command clicking the methods take me to the Swift header and they're not declared there.
My other option would be to type _stdlib and wait for autocomplete or control space to see my options. Unfortunately, none of these methods autocomplete.
Is there a file where these and other stdlib functions are declared, or is there documentation for these methods anywhere?

I found the answer to my question via a tips and tricks blog post from realm here -- notably, the post by JP Simard.
The best way to see other methods along these lines is to go to your terminal and type:
cd `xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
And then enter the following:
nm -a libswiftCore.dylib | grep "T _swift_stdlib"
This will give you a readout of all available functions that looks something like this:
00000000001a43c0 T _swift_stdlib_NSObject_isEqual
00000000001a4490 T _swift_stdlib_NSStringHasPrefixNFD
00000000001a44f0 T _swift_stdlib_NSStringHasSuffixNFD
00000000001a4450 T _swift_stdlib_NSStringNFDHashValue
00000000001a2650 T _swift_stdlib_atomicCompareExchangeStrongPtr
00000000001a2670 T _swift_stdlib_atomicCompareExchangeStrongUInt32
00000000001a2690 T _swift_stdlib_atomicCompareExchangeStrongUInt64
00000000001a2700 T _swift_stdlib_atomicFetchAddUInt32
00000000001a2710 T _swift_stdlib_atomicFetchAddUInt64
00000000001a26f0 T _swift_stdlib_atomicLoadPtr
00000000001a26d0 T _swift_stdlib_atomicLoadUInt32
00000000001a26e0 T _swift_stdlib_atomicLoadUInt64
00000000001a26b0 T _swift_stdlib_atomicStoreUInt32
00000000001a26c0 T _swift_stdlib_atomicStoreUInt64
00000000001a4410 T _swift_stdlib_compareNSStringDeterministicUnicodeCollation
000000000017c560 T _swift_stdlib_conformsToProtocol
00000000001a5a80 T _swift_stdlib_demangleName
000000000017c8e0 T _swift_stdlib_dynamicCastToExistential1
000000000017c6f0 T _swift_stdlib_dynamicCastToExistential1Unconditional
00000000001a5910 T _swift_stdlib_getTypeName
I haven't found any documentation, but a lot of these function names are fairly explanatory and one can always discover a lot through trying them out!

All answers are good, but the result of second step that we can not use. We dont even know is this function usable or correct...
I've been trapped in these result about 1 day.
Finally I dump all funcitons & symbols for stdlib from libswiftcore.dylib, i found this..
command:
nm libswiftcore.dylib | grep "_stdlib_"
We can find one line from result:
00000000000b2ca0 T __TFSs19_stdlib_getTypeNameU__FQ_SS
Remove first underscore "_" then we get this:
_TFSs19_stdlib_getTypeNameU__FQ_SS
Maybe we can view this website to understand the meaning of "_TFSs19_stdlib_getTypeNameU__FQ_SS",
But I think we can get the correct function description faster!!
So, we demangle like this below in xcode lldb window:
(lldb) p _stdlib_demangleName("_TFSs19_stdlib_getTypeNameU__FQ_SS")
(String) $R0 = "Swift._stdlib_getTypeName <A>(A) -> Swift.String"
Finally we can expose more undocumented functions in swift that we never seen before, we can try another one that we never heard like this:
(lldb) p _stdlib_demangleName("_TFSs24_stdlib_atomicLoadARCRefFT6objectGVSs20UnsafeMutablePointerGSqPSs9AnyObject____GSqPS0___")
(String) $R1 = "Swift._stdlib_atomicLoadARCRef (object : Swift.UnsafeMutablePointer<Swift.Optional<Swift.AnyObject>>) -> Swift.Optional<Swift.AnyObject>"
All clear~ Thank god!!
Share this to you, wish it can help~
:D

Related

Mozilla Deep Speech SST suddenly can't spell

I am using deep speech for speech to text. Up to 0.8.1, when I ran transcriptions like:
byte_encoding = subprocess.check_output(
"deepspeech --model deepspeech-0.8.1-models.pbmm --scorer deepspeech-0.8.1-models.scorer --audio audio/2830-3980-0043.wav", shell=True)
transcription = byte_encoding.decode("utf-8").rstrip("\n")
I would get back results that were pretty good. But since 0.8.2, where the scorer argument was removed, my results are just rife with misspellings that make me think I am now getting a character level model where I used to get a word-level model. The errors are in a direction that looks like the model isn't correctly specified somehow.
Now I when I call:
byte_encoding = subprocess.check_output(
['deepspeech', '--model', 'deepspeech-0.8.2-models.pbmm', '--audio', myfile])
transcription = byte_encoding.decode("utf-8").rstrip("\n")
I now see errors like
endless -> "endules"
service -> "servic"
legacy -> "legaci"
earning -> "erting"
before -> "befir"
I'm not 100% that it is related to removing the scorer from the API, but it is one thing I see changing between releases, and the documentation suggested accuracy improvements in particular.
Short: The scorer matches letter output from the audio to actual words. You shouldn't leave it out.
Long: If you leave out the scorer argument, you won't be able to detect real world sentences as it matches the output from the acoustic model to words and word combinations present in the textual language model that is part of the scorer. And bear in mind that each scorer has specific lm_alpha and lm_beta values that make the search even more accurate.
The 0.8.2 version should be able to take the scorer argument. Otherwise update to 0.9.0, which has it as well. Maybe your environment is changed in a way. I would start in a new dir and venv.
Assuming you are using Python, you could add this to your code:
ds.enableExternalScorer(args.scorer)
ds.setScorerAlphaBeta(args.lm_alpha, args.lm_beta)
And check the example script.

Microsoft Access DoCmd.OutputTo not recognizing acOutPutQuery

Right now, I am just working with powershell, but I plan on porting this concept to JScript and using the .NET jsc with ActiveXObject('Access.Application'). I have opened my query using $accessapp.DoCmd.OpenQuery("MyQuery") and I can see that it is loaded using $accessapp.CurrentData.AllQueries("MyQuery"). I would like to use $accessapp.DoCmd.OutputTo(acOutputQuery, "MyQuery",<acFormat>, <file>), but for some reason, I keep getting the error:
Unexpected token 'acOutputQuery' in expression or statement
Just running $accessapp.DoCmd.OutputTo shows that is what is expected:
void OutputTo (AcOutputObjectType, Variant, Variant, Variant, Variant, Variant, Variant, AcExportQuality)
Every resource I have seen, including the Microsoft OutputTo documentation uses the acOutputObjectType in this manner, so I am completely stumped.
Okay, sorry it took me a while to get back. Thanks to #HansUp for leading me down the correct path. I Used the AcOutputObjectType enumeration link he posted as well as the MS Constants Enumeration. I'll give both a powershell example and an MS JScript one. I'll use acOutputQuery and xcFormatTXT as 1 and "MS-DOS" respectively here, but there are many others in the two links above.
powershell:
$acc = New-Object -com Access.Application
$acc.OpenCurrentDatabase("<path_to_file>.accdb")
$acc.DoCmd.OpenQuery("MyQuery")
$acc.DoCmd.OutputTo(1,"MyQuery","MS-DOS", "<path_to_output_file>.txt")
MS JScript:
function writeToTextFile(dbPath,queryName,outputPath){
var acc = new ActiveXObject("Access.Application"); //create new COM instance
acc.OpenCurrentDatabase(dbPath+".accdb"); //open the database
if(!acc.CurrentData.AllQueries(queryName).IsLoaded){
acc.DoCmd.OpenQuery(queryName); //load the query if it is not loaded yet
}
acc.DoCmd.OutputTo(1,queryName,"MS-DOS",outputPath+".txt"); //write to file
}
These two are kind of quick and dirty. Since I have this working in JScript now, I will probably make a writeToFile() function that takes the format as an argument. I considered using an object to map the name string to the enumeration, but I don't know how useful that would actually be. I suppose if you wanted, you could take the output object as an argument, too, but I only plan to use query objects for now.

Latex - Why comments environments do not work in macros?

I'm trying to crate a macro that could display different levels of details in a Resume, the idea being to be able to state a specific theme and to get details only for relevant entries in my resume.
I'm using class "memoir" to use the \newcomment function. I tried moderncv, but I was not really convinced.
Here is what I've come up with so far :
\newcomment{Item}
\newcomment{Descr}
\newcomment{Details}
\newcommand{\cvitem}[3]{
\begin{Item}\textbf{#1}\end{Item}
\begin{Descr}\hspace{1cm} {#2}\end{Descr}
\begin{Details}\\ {\small #3}\end{Details}\vspace{2em}
}
\commentsoff{Item}
\commentsoff{Descr}
\commentsoff{Details}
It works as is, but if I state
\commentson{Details}
Then I get the error :
! File ended while scanning use of \next.
<inserted text>
\par
<*> cv_master.tex
I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.
Any idea why ?
You're better of using conditionals in the traditional sense. That is, use \if-like statements that you can toggle on/off:
\documentclass{article}
\newif\ifItem
\newif\ifDescr
\newif\ifDetails
\newcommand{\cvitem}[3]{%
\ifItem
\textbf{#1}
\fi
\ifDescr
\hspace{1cm} #2
\fi
\ifDetails
\\ {\small #3}
\fi
\vspace{2em}
}
\Itemtrue
\Descrtrue
\Detailsfalse
\begin{document}
\cvitem{First}{Second}{Third}
\end{document}
Why? It's easier and works in all environments/classes.

Swift - Getting Error while using replacingOccurrence

So I'm taking Udacity's Swift for Developers course. I attempted to look at the forums for this question but oddly, they were quiet. This is the programming prompt:
var forwardString = "stressed"
var backwardsString = forwardString.characters.reversed()
print(backwardsString)
var lottaLikes = "If likeyou wanna learn Swift likeyou should build lots of small apps cuz it's likea good way to practice."
var noLikes = lottaLikes.replacingOccurrences(of:"like", with:"")
print(noLikes)
For whatever reason, I keep getting this error message:
Be sure that you have replaced all occurences of the word "like" and removed any extra spaces.
What am I missing here? If you need clarification on this I would be happy to provide it.
Thank you
It may be that your code gets the job done, but only because your variable lottaLikes is written in a weird way. You usually would have two spaces surrounding the word "like" so just removing the word would leave 2 spaces in a row. I would suggest writing the following line:
var noLikes = lottaLikes.replacingOccurrences(of:"like ", with:"")
It may be that Udacity is not checking the actual output, but the code itself. If so, It may be looking for something like I wrote above.
If this still does not work, you may want to write another line like so:
var noExtraSpaces = noLikes.replacingOccurences(of: " ", with: " ")

How to get list of available functions and their parameters in KDB/Q?

How would I go about getting a list of available functions and their parameters in a given namespace?
http://code.kx.com/q/ref/syscmds/#f-functions
\f .
\f .namspace
For functions you will have to check parameters individually by just giving the name of function
.n.function
will give you not only the parameters but the whole function definition.
this can surely be improved upon, but thought I'd share as a quick way to get the ball rolling. This will retrieve every global user defined function in every workspace and create a dictionary of namespapaces to functions to parameters.
q)getparams:{k!{n[w]!#'[;1] value each f w:where 100h=type each f:get each ".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:key `}
q)f1:{x+y+z}
q).n1.f2:{x*x}
q).n1.a:2
q).n2.f3:{y+y}
q)show r:getparams[]
q | `aj`aj0`asc`asof`avgs`cols`cor`cov`cross`cut`desc`dev`each`ej`except`fby`..
Q | `Cf`IN`L`S`V`addmonths`bv`chk`cn`d0`dd`def`dpft`dpt`dsftg`dt`en`f`fc`ff`f..
h | `cd`code`data`eb`ec`ed`edsn`es`fram`ha`hb`hc`hn`hr`ht`hta`htac`htc`html`h..
n1| (,`f2)!,,`x
n2| (,`f3)!,`x`y
q)r[`n1;`f2]
,`x
[EDIT] the original function was wrong. It missed the global namespace (`) and didn't capture composition, or functions defined with an adverb. The below corrects this, but seems overly convoluted. I'll still leave it here though in case anyone wants to post a nicer solution (so that I too can learn from that)
getparams:{k!{n[w][w2]!#'[;1] v w2:where 0h=type each v:value/[{type[x] in y}[;t]; ] each f:f w:where in[ ;(t:"h"$100,105+til 7)] type each f:get each `$".",/:"." sv/:string x,/:n:y x}[;m] each key m:k!system each "f .",/:string k:`,key `}
I addition to Naveen's answer, you can call value functionName which will give you a list of items, e.g. parameter names and the compiled byte code